static
and templates
folder in the apps may should also contain a folder with the name of app ex. blog
this is a convention used to prevent namespace pollution, so we reference the files like /blog/base.html
rather than /base.html
which provides more clarity about the file we are referencing and preserves namespace.
Example: templates
folder inside blog
and search
applications contains a file with name base.html
, and when referencing the file in views
your application gets confused in which file to render.
(Project Structure)
.../project/
apps/
blog/
templates/
base.html
search/
templates/
base.html
(blog/views.py)
def some_func(request):
return render(request, "/base.html")
(search/views.py)
def some_func(request):
return render(request, "/base.html")
## After creating a folder inside /blog/templates/(blog) ##
(Project Structure)
.../project/
apps/
blog/
templates/
blog/
base.html
search/
templates/
search/
base.html
(blog/views.py)
def some_func(request):
return render(request, "/blog/base.html")
(search/views.py)
def some_func(request):
return render(request, "/search/base.html")