Moving django apps into subfolder and url.py error

后端 未结 4 918
梦谈多话
梦谈多话 2021-02-13 13:33

I have a question about putting django apps into \"apps\" subdirectory. I have the app called “faktura” in a project_root. I didn’t like the fact it lies there and I want to sto

4条回答
  •  有刺的猬
    2021-02-13 14:11

    Use BASE_DIR variable from the settings.py. It should be already defined:

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

    Better not use the __file__ attribute in manage.py and wsgi.py, as they are located in different directories.

    So, just add the following to manage.py and wsgi.py (and to the celery.py if you use Celery):

        from django.conf import settings
        sys.path.append(os.path.join(settings.BASE_DIR, "apps"))
    

    You will end up with the following project structure:

    project
    ├── project
    │   ├── __init__.py
    │   ├── celery.py
    │   ├── settings.py
    │   ├── urls.py
    │   └── wsgi.py
    ├── apps
    │   ├── app1
    │   └── app2
    └── manage.py
    

提交回复
热议问题