[Django]-Django load wrong template

3👍

Typically you write the name of the app under the templates directory, so:

faq/
  templates/
    faq/
      index.html

This creates a sort of "namespace", such that you can reference to the correct file with:

from django.shortcuts import render

def index_view(request):
    return render(request, 'faq/index.html')

If you do not construct such directory, then Djangno will simply search for a file named index.html in all the template directories. So if there are multiple, it depends on the order in which the template directories are searched.

Leave a comment