Reputation: 3064
I wrote a django web application and now I need to translate it to english. I followed the documentation but I keep getting this strange error:
ImproperlyConfigured at /i18n/setlang/ settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. Request Method: POST Request URL: http://192.92.149.139:8000/i18n/setlang/ Django Version: 2.0.3 Exception Type: ImproperlyConfigured Exception Value:
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. Exception Location: /home/mwon/venvs/arquivo/lib/python3.6/site-packages/django/db/backends/dummy/base.py in complain, line 20 Python Executable: /home/mwon/venvs/arquivo/bin/python3.6 Python Version: 3.6.4 Python Path: ['/home/mwon/digitalocean/website_dev', '/home/mwon/venvs/arquivo/lib/python36.zip', '/home/mwon/venvs/arquivo/lib/python3.6', '/home/mwon/venvs/arquivo/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/django_styleguide-1.2.5-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/Markdown-2.6.11-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/bs4-0.0.1-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/beautifulsoup4-4.6.0-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/duc_preprocess-1.0-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/simple_cnlp-1.0-py3.6.egg', '/home/mwon/venvs/arquivo/lib/python3.6/site-packages/django_mongoengine-0.3-py3.6.egg'] Server time: Qua, 5 Set 2018 11:21:17 +0000
EDIT: and the settings.DATABASES:
{
'default': {
'ENGINE': 'django.db.backends.dummy',
'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'OPTIONS': {},
'TIME_ZONE': None,
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'TEST': {
'CHARSET': None, 'COLLATION': None, 'NAME': None, 'MIRROR': None
}
}
}
This is my urls.py:
urlpatterns = [
path('i18n/',include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns(
path('admin/',admin.site.urls),
path('',include('arquivo.urls')),
prefix_default_language = True
)
and settings.py:
LANGUAGE_CODE = 'pt'
LANGUAGES = (
('en', 'English'),
('pt', 'Portuguese'),
)
USE_I18N = True
LOCALE_PATHS = [
os.path.join(BASE_DIR,'locale')
]
The translation seems to be working fine. The problem was when I included a form to select the language. I used the example code from documentation:
{% load i18n %}
<form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}">
<select name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input type="submit" value="Go">
</form>
Upvotes: 0
Views: 467
Reputation: 3064
Ok, so the problem was related with sessions. I'm using a MongoDB database with Django-MongoEngine and didn't turn on sessions support. So just added these two lines of code
SESSION_ENGINE = 'django_mongoengine.sessions'
SESSION_SERIALIZER = 'django_mongoengine.sessions.BSONSerializer'
to settings.py
and everything started to work fine.
Upvotes: 0