django-admin runserver抛出错误

时间:2017-11-30 13:24:48

标签: python django mongodb

我已经安装了

  • 的Django == 1.10.0
  • pymongo == 2.7.1
  • MongoDB 2.6
  • 的Python == 2.7
  • 6 == 1.10.0
  • MongoDB 2.6
  • mongoengine == 0.9.0

mysite/mysite/settings.py我添加了

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
    'default': {
        #'ENGINE': 'django_mongodb_engine',
    'ENGINE': 'django.db.backends.dummy',
        'NAME': 'test',
        'USER': 'admin',
        'PASSWORD': 'smmis@123#',
            }
}

#start
AUTHENTICATION_BACKENDS = (
    'mongoengine.django.auth.MongoEngineBackend',
)
from mongoengine import *
    connect('test')
   # connect('test', host='mongodb://127.0.0.1',  port=50226)
#end

当我运行django-admin runserver时会抛出错误

Traceback (most recent call last):
  File "/opt/VirEnv_p2.7/bin/django-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/core/management/base.py", line 317, in run_from_argv
    connections.close_all()
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/db/utils.py", line 229, in close_all
    for alias in self:
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/db/utils.py", line 223, in __iter__
    return iter(self.databases)
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/db/utils.py", line 156, in databases
    self._databases = settings.DATABASES
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/VirEnv_p2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 116, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

尽管SECRET_KEY = '9&q3vm=wpl3&r_8vgqch3*$+h*kp+urol&z=!gk*79lhwvjx'位于mysite/settings.py

我错过了什么我是Django的新手

enter image description here

1 个答案:

答案 0 :(得分:0)

django-admin默认情况下不设置您要使用的设置文件。

您可以django-admin runserver --settings=mysite.settings或者您可以使用python manage.py runserver(manage.py将设置文件设置为其帮助程序功能的一部分)。

或者,我实际上更喜欢使用django-admin,但后来我使用名为direnvhttps://direnv.net/)的lib在我的项目文件夹的上下文中设置DJANGO_SETTINGS_MODULE环境变量。

https://docs.djangoproject.com/en/1.11/ref/django-admin/