我已经安装了
在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的新手
答案 0 :(得分:0)
django-admin默认情况下不设置您要使用的设置文件。
您可以django-admin runserver --settings=mysite.settings
或者您可以使用python manage.py runserver
(manage.py将设置文件设置为其帮助程序功能的一部分)。
或者,我实际上更喜欢使用django-admin,但后来我使用名为direnv
(https://direnv.net/)的lib在我的项目文件夹的上下文中设置DJANGO_SETTINGS_MODULE
环境变量。