steve254 steve254 - 1 month ago 10
Linux Question

Django, 1.9.10 Language matching query does not exist

I am a struggling beginner and I will appreciate your help.
I have cloned a Django site to edit and learn from it but I can not runserver.
On running server I get the error

Language matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/en/software/features
Django Version: 1.9.10
Exception Type: DoesNotExist
Exception Value:

Language matching query does not exist.
Exception Location: /home/steve/Documents/wger/venv-django/lib/python3.5/site-packages/django/db/models/query.py in get, line 387
Python Executable: /home/steve/Documents/wger/venv-django/bin/python
Python Version: 3.5.2
Python Path:

['/home/steve/Documents/wger/wger-croners',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/home/steve/Documents/wger/venv-django/lib/python3.5/site-packages',
'/home/steve/.config/wger']
Server time: Mon, 24 Oct 2016 19:48:24 +0300


/home/steve/Documents/wger/wger-croners/wger/utils/language.py in load_language
language = Language.objects.get(short_name=used_language)


What could be wrong? I have followed all instructions on the Git readme.

Answer

It is because there is no entry in Language model where short_name equals to used_language. For details, read: Retrieve Object from Django Model

In case you want to create object with short_hand asused_language in case not found, use .get_or_create() instead as:

 language, is_created = Language.objects.get_or_create(short_name=used_language)