生产环境Django项目目录结构设置及文件位置咨询
Hey there! Let's sort out this directory structure confusion so your production deployment on DigitalOcean goes smoothly.
First: Which manage.py Should You Use?
You should only have one root manage.py for your entire Django project—this is the single entry point for all core commands (migrations, collectstatic, running the server, etc.). Having two manage.py files means your current setup is misaligned with Django's standard project layout, so we need to fix that first.
Step 1: Clarify What’s in the Bitbucket app Directory
First, figure out if the app directory you imported from Bitbucket is:
- A full Django project (contains
settings.py/settingsdirectory, rooturls.py, and its ownmanage.py), or - A single Django app (only has app-specific files like
models.py,views.py,templates—no project-level settings ormanage.py)
To check quickly:
- Run
ls /home/zorgan/project/app—if you seesettings.pyor asettingsfolder, it’s a full project. - If you only see app-specific files (no project config), it’s just a standalone app.
Step 2: Fix the Directory Structure
Based on what you find above, here’s how to adjust:
Case 1: The Bitbucket app is a Full Django Project
This means the outer /home/zorgan/project/manage.py is probably a leftover from a blank project you created earlier. Do this:
- Move all contents from
/home/zorgan/project/app/directly into/home/zorgan/project/(so yourmanage.py, settings, and business code live under the project root). - Delete the now-empty
appdirectory. - Double-check your virtual environment (
env) uses the project’s dependencies—runpip install -r requirements.txtif there’s a requirements file in the moved code. - Verify
wsgi.py/asgi.pypoints to the correct settings module (e.g.,myproject.settingswheremyprojectis the directory holding your settings).
Case 2: The Bitbucket app is a Single Django App
Here, the outer /home/zorgan/project/manage.py is your project root entry point. Do this:
- Create a new directory under
/home/zorgan/project/(e.g.,business_app). - Move all app-specific files from
/home/zorgan/project/app/into this new directory. - Delete the old
appdirectory. - Add the new app name to
INSTALLED_APPSin your rootsettings.py(e.g.,'business_app'). - Test the setup by running
python manage.py makemigrations—it should detect any models in the new app.
Production Deployment Tips
- Always activate your virtual environment (
source /home/zorgan/project/env/bin/activate) before running Django commands to avoid dependency conflicts. - For static files, set
STATIC_ROOTinsettings.pyto/home/zorgan/project/static, then runpython manage.py collectstaticto gather all assets into this directory (required for production servers like Nginx). - When setting up Gunicorn/uWSGI, point it to your root project’s WSGI module (e.g.,
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application—replacemyprojectwith your actual settings directory name).
Final Note
Aligning your directory structure with Django’s standards will make debugging, deploying, and maintaining your app much easier long-term. Stick to one root manage.py, keep your project config and apps organized, and you’ll be set for production.
内容的提问来源于stack exchange,提问作者Zorgan

