问题
I'm developing a new Django site. It uses some existing Django apps and I'm building some of my own.
Current folder structure (truncated):
projects/
- mysite/
- .git/
- conf/
- mysite/
- __init__.py
- settings.py
- myapp/
- __init__.py
- admin.py
- models.py
- manage.py
I'd like to make my site and apps available as separate Git repositories. In other words, someone may want to clone/contribute to the whole site, or they may want to clone/contribute to just an app.
According to the Packaging your app section of Advanced tutorial: How to write reusable apps the following folder structure is required for separate site and app folders:
projects/
- mysite/
- .git/
- conf/
- mysite/
- __init__.py
- settings.py
- manage.py
- django-myapp
- .git/
- myapp/
- __init__.py
- admin.py
- models.py
- setup.py
But in Using your own package the same tutorial suggests that the only way to make and use local modifications is to:
- Modify the app folder
- Run
python setup.py sdist
to build the app - Run
pip install --user /path/to/django-myapp.tar.gz
to install it - Run the Django site
How can I organise these folders so that I can easily modify either site or app code, and immediately run the site locally? In other words, avoid building and importing a local tarball each time.
回答1:
My naive reading is that the following (untested) structure should work, with myapp
excluded from the virtualenv used to run the site locally...
projects/
- mysite/
- .git/
- conf/
- mysite/
- __init__.py
- settings.py
- myapp/ --> symlink to projects/django-myapp/myapp
- .gitignore --> ignores myapp/
- manage.py
- django-myapp
- .git/
- myapp/
- __init__.py
- admin.py
- models.py
- setup.py
Obviously releases should be tested and coordinated carefully, so that released versions and published dependencies work together correctly.
来源:https://stackoverflow.com/questions/51248538/how-can-i-run-a-local-django-site-with-a-separate-app-folder