繁体   English   中英

Django runserver 命令失败

[英]Django runserver command failed

我已经学习 Python 几个月了,几天前我决定学习 Web 框架之一。 我在 Django 上找到了一些教程,在我尝试使用“runserver”命令之前它看起来真的很酷。 如您所见,我使用了基本行“python -m django runserver manage.py”并接到了很多电话。 我刚刚安装了 Django 并且我没有更改它的脚本中的任何内容。 我只是从创建一个与“python -m django startproject djangoLearn”完美配合的新项目开始。 您对如何解决此问题有任何想法吗? 这个问题使我无法进一步学习,因为我看不到自己的项目:((提前致谢。希望你们今天过得愉快。我在尝试运行服务器时接到的电话:

D:\Projects\djangoLearn>python -m django runserver manage.py
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main 
    return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\__main__.py", line 9, in <module>
    management.execute_from_command_line()
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\commands\runserver.py", line 61, in execute
    super().execute(*args, **options)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\core\management\commands\runserver.py", line 68, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\conf\__init__.py", line 82, in __getattr__
    self._setup(name)
File "C:\Users\norml\AppData\Roaming\Python\Python39\site-packages\django\conf\__init__.py", line 63, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我希望您的 virtualenv 已激活? 使用它来创建项目django-admin startproject projectname. 请注意它在没有期间的情况下工作的期间。

使用python manage.py startapp appname创建一个应用 别忘了在 INSTALLED_APP 中注册该应用

我认为您要使用的代码是python manage.py runserver

但是如果你使用 python3 使用python3 manage.py runserver只需在manage.py runserver之前使用你使用的任何东西来启动你的 python

您应该首先激活您的虚拟环境。 在 linux 中使用这样的命令:

source "path-to-activate-file"

在 windows 中这样的命令:

\pathto\env\Scripts\activate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM