[英]Does my Django app have to be the same name as the project directory?
I've pulled my django repo from bitbucket onto my digital ocean server. 我已经将我的Django存储库从bitbucket拉到了数字海洋服务器上。 My project folder name in my server is project
whereas my initial app from my repo (the one with settings.py
is called app
. Does this cause any problems? Because I know when you create a django project offline, the first directory is always the same as the parent directory. 我在服务器中的项目文件夹名称是project
而我在仓库中的初始应用程序(带有settings.py
的app
称为app
。这会导致任何问题吗?因为我知道在离线创建django项目时,第一个目录始终是与父目录相同。
There won't be any issue with having the different name of parent directory and the project directory (the one with settings.py). 父目录和项目目录的名称(与settings.py相同)不会有任何问题。 You can try renaming the parent directory and it would still work the same way but the name of project directory should not be touched since the same is linked with project settings which are used to run the project. 您可以尝试重命名父目录,它仍然可以以相同的方式工作,但是不应触摸项目目录的名称,因为该名称与用于运行项目的项目设置链接在一起。
whereas my initial app from my repo (the one with settings.py 而我的仓库中的第一个应用程序(带有settings.py的应用程序
That's not an application, that's your project's configuration. 那不是应用程序,那是您项目的配置。
And no, having the same name for your project's root directory and it's configuration directory shouldn't cause any problem. 不,项目的根目录和配置目录具有相同的名称不会造成任何问题。
That's even how it's designed to be so it's perfectly normal. 这甚至是设计成完全正常的方式。
Since the wsgi.py (which should be what you use for production) dynamically handles path as long as the internal structure of your project is preserved (don't rename the project's configuration directory). 由于wsgi.py(应该是您用于生产的内容)可以动态处理路径,因此只要保留了项目的内部结构即可(不要重命名项目的配置目录)。
The absolute path to your project isn't hardcoded, it's retrieved by getting parent directories of your configuration directory. 项目的绝对路径不是硬编码的,它是通过获取配置目录的父目录来检索的。 You can move your project and even rename its root directory. 您可以移动项目,甚至重命名其根目录。
Here is how it's handled : 处理方法如下:
wsgi.py : wsgi.py :
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
wsgi.py
sets the right value to use the right settings.py
file. wsgi.py
设置正确的值以使用正确的settings.py
文件。
settings.py : settings.py :
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
settings.py
sets BASE_DIR
dynamically. settings.py
动态设置BASE_DIR
。 This value is then what's used for handling pathes to avoid having an hardcoded absolute path that wouldn't work as soon as you move your project. 然后,此值将用于处理路径,以避免硬编码的绝对路径在您移动项目后立即无法使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.