相关文章推荐
难过的春卷  ·  cover-view设置overflow: ...·  6 月前    · 
有情有义的葡萄酒  ·  Java ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams In addition to what Robert Townley mentioned, I'd like to add that adding your app to INSTALLED_APPS also helps by making your app's templates discoverable. The default DjangoTemplates backend looks for the 'templates' folder only within the apps included in INSTALLED_APPS. Amos P Nov 1, 2021 at 10:46

Django uses INSTALLED_APPS as a list of all of the places to look for models, management commands, tests, and other utilities.

If you made two apps (say myapp and myuninstalledapp ), but only one was listed in INSTALLED_APPS , you'd notice the following behavior:

  • The models contained in myuninstalledapp/models.py would never trigger migration changes (or generate initial migrations). You wouldn't be able to interact with them on the database level either because their tables will have never been created.
  • Static files listed within myapp/static/ would be discovered as part of collectstatic or the test server's staticfiles serving, but myuninstalledapp/static files wouldn't be.
  • Tests within myapp/tests.py would run but myuninstalledapp/tests.py wouldn't.
  • Management commands listed in myuninstalledapp/management/commands/ wouldn't be discovered.
  • So really, you're welcome to have folders within your Django project that aren't installed apps (you can even create them with python manage.py startapp ) but just know that certain auto-discovery Django utilities won't work for that application.

    Additional to point 1: reverse relationships wouldn't be created for models which are pointed to by ForeignKeys from myuninstalledapp. Daniel Roseman Dec 7, 2017 at 7:34

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .