简体   繁体   English

我的Django应用程序必须与项目目录名称相同吗?

[英]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.pyapp称为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.

相关问题 heroku应用程序必须与django项目共享相同的名称吗? - Does heroku app have to share the same name as django project? 我的 django 项目没有从同一目录导入文件 - My django project is not importing files from the same directory Django 1.7 - 应用“your_app_name”没有迁移 - Django 1.7 - App 'your_app_name' does not have migrations 为什么 django 继续将我的应用程序命名为以前的名称? - Why does django continues naming my app as the previous name? 为什么Django将2个文件夹命名为项目名称? - Why does Django name 2 folders the project name? 同一个 Django App 中的多个域和多个目录 - Multiple Domain and Multi Directory in the same Django App 如何在Django中从项目级别包导入而又不与同名的应用程序级别模块冲突? - How to import from project level package in Django without conflicting with app level module with same name? Django:每次我开发 django 应用程序时都必须打开虚拟环境吗 - Django: Does the virtual environment have to be on every time i develop my django app Django迁移应用程序名称的更改(活动项目) - Django Migrate Change of App Name (active project) django collectstatic 在 django 项目中的每个应用程序中查找资产目录 - Django collectstatic to look for assets directory in every app in django project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM