【问题标题】:Probkem in Django with runserver command使用 runserver 命令在 Django 中出现问题
【发布时间】:2022-01-15 19:30:34
【问题描述】:

我在 django 中启动了一个项目,一切正常,但是我关闭了我的项目,几天后我尝试重新打开,但是当我输入命令“django-admin runserver”时出现此错误:

Traceback (most recent call last):
  File "c:\users\moren\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\moren\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\moren\Envs\myapp\Scripts\django-admin.exe\__main__.py", line 7, in <module>
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
    super().execute(*args, **options)
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\core\management\commands\runserver.py", line 68, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
    self._setup(name)
  File "C:\Users\moren\Envs\myapp\lib\site-packages\django\conf\__init__.py", line 67, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
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.

当我输入“python manage.py runserver”时,会出现:

c:\users\moren\appdata\local\programs\python\python37-32\python.exe: can't open file 'manage.py': [Errno 2] No such file or directory

如果有人可以帮助我,我将非常感激

【问题讨论】:

标签: python python-3.x django web web-deployment


【解决方案1】:

您需要 cd 进入您的项目并再次运行该命令,所以简而言之,应该在模块“manage.py”所在的位置执行命令python manage.py runserver

【讨论】:

  • 我觉得我做到了,但你能给我举个例子来告诉我如何做到这一点吗?
  • 什么意思?你激活你的虚拟环境了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-30
  • 1970-01-01
  • 2020-01-30
  • 2019-03-16
相关资源
最近更新 更多