Django template does not exist, although it shows that the file exists,

I cannot display any html pages in Django 1.7. My 'index.html' is in ' project/seatalloc/templates/index.html ', and my view.py in project/seatalloc/views.py looks like this:

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

project / project / settings.py has a set of template templates:

 TEMPLATE_DIRS = ( '/Users/Palak/Desktop/academics/sem3/cs251/lab11/project/seatalloc/templates', ) 

urls.py:

 urlpatterns = patterns('', url(r'^seatalloc/', include('seatalloc.urls')), url(r'^admin/', include(admin.site.urls)), ) 

Template loader

I tried to strictly follow the documentation, but can't figure out if Django is detecting the file, why am I getting TemplateDoesNotExist in / seatalloc / error. I am new to Django, someone can help.

+5
source share
3 answers

If - as in your case - you get a TemplateDoesNotExist error and the debug page says “File exists” next to the corresponding template, this usually (always?) Means that this template refers to another template that cannot be found.

In your case, index.html contains a statement ( {% extends %}, {% include %}, ... ) that refers to another template that Django cannot find. Unfortunately, with Django 1.8.3, the debug page always indicates the base template, not the one that Django cannot find.

+27
source

Try it,

 import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates/'), ) 
+2
source

First of all, do not use the static path (fixed path) in the dirs templates in settings.py, use:

 BASE_DIR = os.path.dirname(os.path.dirname(__file__)) TEMPLATE_DIRS = ( BASE_DIR +'/Templates', ) 

And the template directory should be in the project directory in which the manage.py file is located.

And in view.py use render_to_response instead of render .

 return render_to_response("index.html") 
-1
source

Source: https://habr.com/ru/post/1205673/


All Articles