[英]Project Structure for Django Application
I am new to Django and using Pycharm from IntelliJ as my IDE. 我是Django的新手,并使用IntelliJ的Pycharm作为我的IDE。 When typing:
输入时:
$ django-admin startproject mysite $ django-admin startproject mysite
the following project structure is generated: 生成以下项目结构:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
This doesn't quite make sense since the files settings.py, urls.py, and wsgi.py are project specific, not app or package specific. 这没有多大意义,因为文件settings.py,urls.py和wsgi.py是项目特定的,而不是app或特定于包。 Hence, they should go in the root folder just like manage.py.
因此,它们应该像manage.py一样进入根文件夹。 Please advise.
请指教。 Thanks.
谢谢。
That is the typical project layout, as you can see in the tutorial . 这是典型的项目布局,如教程中所示 。
You can change the layout if you want, but I recommend that you don't. 如果需要,您可以更改布局,但我建议您不要。 If you moved
settings.py
that would confuse manage.py
, if you moved urls.py
then you'd have to update ROOT_URLCONF
in settings.py
, and so on. 如果你移动了
settings.py
会使manage.py
混淆,如果你移动了urls.py
那么你必须在settings.py
更新ROOT_URLCONF
,依此类推。
If you wish to store your settings.py
, url.py
and wsgi.py
files in the root project directory with manage.py
you can do so, but you will have to make a couple of alterations to the settings.py
file and the way you run your project locally. 如果您希望使用
manage.py
在根项目目录中存储settings.py
, url.py
和wsgi.py
文件,则可以这样做,但是您必须对settings.py
文件进行一些更改,在本地运行项目的方式。
use python manage.py runserver --settings=settings
(instead of the default python manage.py runserver -settings=mysite.settings
) to tell Django to use a settings file in the root project directory. 使用
python manage.py runserver --settings=settings
(而不是默认的python manage.py runserver -settings=mysite.settings
)告诉Django使用根项目目录中的设置文件。
change ROOT_URLCONF
in settings.py
from 'mysite.urls'
to 'urls'
. 改变
ROOT_URLCONF
在settings.py
从'mysite.urls'
到'urls'
。
change WSGI_APPLICATION
in settings.py
from 'mysite.wsgi.application'
to 'wsgi.application'
. 改变
WSGI_APPLICATION
在settings.py
从'mysite.wsgi.application'
到'wsgi.application'
。
Depending on preferences, it is actually relatively common to change the structure of your project (within reason). 根据偏好,改变项目结构(在合理范围内)实际上是相对常见的。 For example, the well-read Django book Two Scoops of Django suggests that you store different versions of your
settings.py
files in a mysite/settings
as follows (ignoring urls/wsgi/apps for the moment): 例如,精心阅读的Django书中的两个Scoops of Django建议您在
mysite/settings
存储不同版本的settings.py
文件,如下所示(暂时忽略urls / wsgi / apps):
mysite/
manage.py
settings/
base.py
local.py
staging.py
production.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.