简体   繁体   English

Django runserver 命令失败

[英]Django runserver command failed

I've been learning Python for a few months and a couple days ago i decided to learn one of Web frameworks.我已经学习 Python 几个月了,几天前我决定学习 Web 框架之一。 I found some tutorials on Django and it was looking really cool until i tried to use "runserver" command.我在 Django 上找到了一些教程,在我尝试使用“runserver”命令之前它看起来真的很酷。 As you can see i used the basic line "python -m django runserver manage.py" and got a lot of calls.如您所见,我使用了基本行“python -m django runserver manage.py”并接到了很多电话。 I've just installed Django and i wasn't changing anything in it's scripts.我刚刚安装了 Django 并且我没有更改它的脚本中的任何内容。 I only started by creating a new project that worked perfectly with "python -m django startproject djangoLearn".我只是从创建一个与“python -m django startproject djangoLearn”完美配合的新项目开始。 Do you have any thoughts on how can i fix this problem?您对如何解决此问题有任何想法吗? This problem prevents me from further learning beacuse i can't see my own project:(( Thanks in advance. Hope y'all have a great day. Calls that i get while trying to run server:这个问题使我无法进一步学习,因为我看不到自己的项目:((提前致谢。希望你们今天过得愉快。我在尝试运行服务器时接到的电话:

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.

I hope your virtualenv is activated??我希望您的 virtualenv 已激活? use this to create project django-admin startproject projectname.使用它来创建项目django-admin startproject projectname. take note of the period it works without the period though.请注意它在没有期间的情况下工作的期间。

use python manage.py startapp appname to create an app don't forget to register the app in INSTALLED_APP使用python manage.py startapp appname创建一个应用 别忘了在 INSTALLED_APP 中注册该应用

i think the code you want to use is python manage.py runserver我认为您要使用的代码是python manage.py runserver

but if you use python3 use python3 manage.py runserver just use whatever you use to start your python before manage.py runserver但是如果你使用 python3 使用python3 manage.py runserver只需在manage.py runserver之前使用你使用的任何东西来启动你的 python

you should first activate your virtual environment.您应该首先激活您的虚拟环境。 with a command like this in linux:在 linux 中使用这样的命令:

source "path-to-activate-file"

and command like this in windows:在 windows 中这样的命令:

\pathto\env\Scripts\activate

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

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