gpt4 book ai didi

python - "python manage.py runserver"与 "django-admin runserver"

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:41 26 4
gpt4 key购买 nike

我安装了一个应用程序 Scaffold,当我使用 python manage.py runserver 时它运行完美,但是当我尝试使用 django-admin 启动它时,它失败了;

You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我尝试用 django-admin migrate --settings=scaffold.settings 调用它我明白了; ImportError:没有名为 scaffold.settings 的模块

我已经尝试了多种方法,四处搜索,但似乎无法弄清楚我需要更改什么。 settings.py 文件位于目录 ..\scaffold 中,但我不再确定这是我需要使用的文件。

最佳答案

你应该使用 manage.py 除非有特定的原因不需要特定项目的配置。根据docs

manage.py is automatically created in each Django project. manage.py is a thin wrapper around django-admin that takes care of several things for you before delegating to django-admin:

  • It puts your project’s package on sys.path.
  • It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.
  • It calls django.setup() to initialize various internals of Django.

关于python - "python manage.py runserver"与 "django-admin runserver",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32199621/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com