Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django NEWBIE – TemplateDoesNotExist

(My project directory is called test and the app in question is called posts)

Django tried loading these templates, in this order:

Using engine django:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

django.template.loaders.app_directories.Loader: /path-to-app-dir/virtual/test/posts/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /path-to-app-dir/virtual/platform/lib/python3.10/site-packages/django/contrib/admin/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /path-to-app-dir/virtual/platform/lib/python3.10/site-packages/django/contrib/auth/templates/index.html (Source does not exist)

Views.py

from django.shortcuts import render
from django.http import HttpResponse


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

Urls.py

from django.urls import path
from . import views

urlpatterns=[
    path('', views.index)
]

I have mentioned the app in Settings.py so that probably shouldn’t be an issue.

What am I doing wrong ?

filetree

>Solution :

The template is placed under posts/templates/posts/. If you enable the APP_DIRS, then it will look for all templates/ directories in all apps, but it is still placed under a posts/ directory, hence you access the template with:

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
     return render(request,'posts/index.html')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading