Search code examples
django-templatesdjango-urlsdjango-staticfilesdjango-appsdjango-2.2

How to manage multiple templates with it's static files in multipl apps in django 2.2?


I have Multiple apps, but every app has it's own template with it's own static files , they server one purpose with different kinds of user and uses. the apps are: 1. Portal 2. Portal Blog editor(Its like an admin panel for the writer with analytics and stuff) 3. Main Admin Panel(Not the django one) I am using django 2.2 since I am running Djongo. Please suggest me some solution on this problem along with how do i manage it's urls.


Solution

  • Django supports per-app templates and statics directories.

    1/ In each app, create a templates/yourappname and a static/yourappname directory.

    2/ make sure you have "APP_DIRS": True in your settings.TEMPLATES

    3/ make sure you have 'django.contrib.staticfiles.finders.AppDirectoriesFinder' in you settings.STATICFILES_FINDERS

    4/ Then in your code always refer to your templates and static with the matching appname prefix ie appname/templatename.ext and static/appname/filename.ext