How can I run a local Django site with a separate app folder?

谁说我不能喝 提交于 2020-01-06 06:53:38

问题


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:

  1. Modify the app folder
  2. Run python setup.py sdist to build the app
  3. Run pip install --user /path/to/django-myapp.tar.gz to install it
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!