简体   繁体   中英

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. 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.

There won't be any issue with having the different name of parent directory and the project directory (the one with 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

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).

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 :

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")

wsgi.py sets the right value to use the right settings.py file.

settings.py :

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

settings.py sets BASE_DIR dynamically. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM