我见过许多其他答案,但没有任何帮助。
我尝试过的事情,
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app_name.settings")
在manage.py和wsgi.py文件中。
设置文件中有一个密钥,但仍显示此信息。
我也试过了,
$ export SECRET_KEY='value of secret key'
而且,
import django
django.setup()
还有 init.py 文件。我不知道是什么问题。请帮忙。
我使用mongodb作为数据库后端,它给了我这个错误。
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/luvpreet/Desktop/drf-vogo/new_mongo/new_mongo/settings.py", line 16, in <module>
django.setup()
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 120, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不能为空。
以下更新 -
下面,
(mongo3) luvpreet@DHARI-Inspiron-3542:~/Desktop/drf-vogo/new_mongo$ pip freeze
Django==1.9
django-rest-framework-mongoengine==3.3.1
djangorestframework==3.3.3
mongoengine==0.9.0
pymongo==2.7
Stacktrace,
(mongo3) luvpreet@DHARI-Inspiron-3542:~/Desktop/drf-vogo/new_mongo$ ./manage.py runserver
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/luvpreet/.virtualenvs/mongo3/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/luvpreet/Desktop/drf-vogo/new_mongo/new_mongo/settings.py", line 134, in <module>
mongoengine.connect(
NameError: name 'mongoengine' is not defined