Django“ settings.DATABASES配置不正确”和“ / i18n / setlang /配置不正确”

时间:2018-09-05 11:31:50

标签: python django django-i18n

我写了一个Django Web应用程序,现在我需要将其翻译成英文。我遵循了documentation,但不断收到这个奇怪的错误:

  

在/ i18n / setlang / settings中配置不正确。DATABASES为   配置不正确。请提供引擎值。检查设定   文档以获取更多详细信息。请求方法:POST请求   URL:http://192.92.149.139:8000/i18n/setlang/ Django版本:2.0.3   异常类型:错误配置的异常值:
  settings.DATABASES配置不正确。请提供引擎   值。查看设置文档以获取更多详细信息。例外   位置:/home/mwon/venvs/arquivo/lib/python3.6/site-packages/django/db/backends/dummy/base.py   在抱怨中,第20行Python   可执行文件:/home/mwon/venvs/arquivo/bin/python3.6 Python   版本:3.6.4 Python路径:['/ 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']   服务器时间:Qua,5 Set 2018 11:21:17 +0000

编辑:和设置。数据库:

{
    '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
        }
    }
}

这是我的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
)

和settings.py:

LANGUAGE_CODE = 'pt'    
LANGUAGES = (
    ('en', 'English'),
    ('pt', 'Portuguese'),
)
USE_I18N = True
LOCALE_PATHS = [
    os.path.join(BASE_DIR,'locale')
]

翻译似乎运行良好。问题是当我包括选择语言的表格时。我使用了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>

1 个答案:

答案 0 :(得分:0)

好,所以问题与会话有关。我正在使用带有Django-MongoEngine的MongoDB数据库,并且没有打开会话支持。因此,只需添加这两行代码

func ResizeImageOriginalSize(targetSize: CGSize) -> UIImage {
        var actualHeight: Float = Float(self.size.height)
        var actualWidth: Float = Float(self.size.width)
        let maxHeight: Float = Float(targetSize.height)
        let maxWidth: Float = Float(targetSize.width)
        var imgRatio: Float = actualWidth / actualHeight
        let maxRatio: Float = maxWidth / maxHeight
        var compressionQuality: Float = 0.5
        //50 percent compression

        if actualHeight > maxHeight || actualWidth > maxWidth {
            if imgRatio < maxRatio {
                //adjust width according to maxHeight
                imgRatio = maxHeight / actualHeight
                actualWidth = imgRatio * actualWidth
                actualHeight = maxHeight
            }
            else if imgRatio > maxRatio {
                //adjust height according to maxWidth
                imgRatio = maxWidth / actualWidth
                actualHeight = imgRatio * actualHeight
                actualWidth = maxWidth
            }
            else {
                actualHeight = maxHeight
                actualWidth = maxWidth
                compressionQuality = 1.0
            }
        }
        let rect = CGRect(x: 0.0, y: 0.0, width: CGFloat(actualWidth), height: CGFloat(actualHeight))
        UIGraphicsBeginImageContextWithOptions(rect.size, false, CGFloat(compressionQuality))
        self.draw(in: rect)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage!
    }

SESSION_ENGINE = 'django_mongoengine.sessions' SESSION_SERIALIZER = 'django_mongoengine.sessions.BSONSerializer' ,一切开始正常。