我在cmd中运行服务器时收到错误
我正在使用Windows 7,Python 3.4.3和 Django版本1.8。
>
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_f
rom_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 190, in fetch_com
mand
klass = load_command_class(app_name, subcommand)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 40, in load_comma
nd_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 14, in
<module>
from django.db.migrations.executor import MigrationExecutor
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 6, in <module>
from .loader import MigrationLoader
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 23, in MigrationRec
order
class Migration(models.Model):
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 1081, in __init_
_
super(CharField, self).__init__(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\abc\Desktop\myapp\myapp\settings.py", line 16, in <module>
import django.contrib.auth
File "C:\Python34\lib\site-packages\django\contrib\auth\__init__.py", line 7, in <module>
from django.middleware.csrf import rotate_token
File "C:\Python34\lib\site-packages\django\middleware\csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python34\lib\site-packages\django\utils\cache.py", line 26, in <module>
from django.core.cache import caches
File "C:\Python34\lib\site-packages\django\core\cache\__init__.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 113, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
答案 0 :(得分:2)
我认为错误信息几乎是自我解释的:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
您需要在settings.py文件中设置SECRET_KEY。
答案 1 :(得分:2)
这是Django版本的不兼容问题。当我安装1.5版本和1.9版本的django时,它正在工作但不是1.10和1.8
答案 2 :(得分:1)
如果SECRET_KEY在setttings.py文件中,那么您正在运行不同的设置文件。
使用以下命令:
python manage.py runserver --settings project_name.settings
project_name.settings
是您的设置文件的路径。
您也可以使用settings.py文件中的print
语句进行检查