gpt4 book ai didi

django 应用程序正在运行,但未包含在 settings.py 中

转载 作者:行者123 更新时间:2023-12-01 21:59:50 27 4
gpt4 key购买 nike

我正在阅读他们网站上的 django 教程。

在第一个教程中https://docs.djangoproject.com/en/2.1/intro/tutorial01/他们正在创建一个名为 polls 的应用程序和一个内部 View ,并在运行服务器时显示该 View 。

然而,在第二个教程中https://docs.djangoproject.com/en/2.1/intro/tutorial02/提到该应用程序应添加到 settings.py 的已安装应用程序部分

To include the app in our project, we need to add a reference to its configuration class in the INSTALLED_APPS setting. The PollsConfig class is in the polls/apps.py file, so its dotted path is 'polls.apps.PollsConfig'. Edit the mysite/settings.py file and add that dotted path to the INSTALLED_APPS setting.

我不确定在第一个教程中它是如何工作的,但不包含该应用程序。包含该应用程序不是强制性的吗?还是仅在特定用例中是强制性的?

谢谢

最佳答案

如果您只需要显示应用程序的一些静态 View ,定义 url 就足够了(这可以在主 urls 本身中完成)。但是,如果您的应用程序有一些模型并且您需要将其包含在 migrate 命令中(并创建其表),则需要将其包含在 installed_apps 中。

关于django 应用程序正在运行,但未包含在 settings.py 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974463/

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