Reputation: 83
I am using python 3.7.2 and Django 2.1 and every time I try to load the home url I get the following error.
TemplateDoesNotExist at /
ghostwriters/post_list.html
Request Method: GET Request URL: http://localhost:8080/ Django Version: 2.1 Exception Type: TemplateDoesNotExist Exception Value:
ghostwriters/post_list.html
Exception Location: C:\Users\User.virtualenvs\ghostwriter-HT06mH6q\lib\site-packages\django\template\loader.py in select_template, line 47 Python Executable: C:\Users\User.virtualenvs\ghostwriter-HT06mH6q\Scripts\python.exe
Doesn't make any sense because there really is no post_list.html and its not in my app level urls.py or my views.py so why is this happening?
urls.py:
from django.urls import path from .views import PostListView
urlpatterns = [ path('', PostListView.as_view(), name='home'), ]
views.py:
from django.shortcuts import render from django.views.generic import ListView
from .models import Post
class PostListView(ListView): model = Post template = 'home.html'
settings.py:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True,
Upvotes: 2
Views: 931
Reputation: 878
If you are using any CBV(Class Based Views), by default django will look for template with some specific pattern. In your case, since you are using List View, it will look for YOURMODELNAME_list.html (YOURMODELNAME in lowercase), If you are extending Detail View, it will look for YOURMODELNAME_detail.html .if you want to override this behavior, within your CBV try this,
class YourCBV(ListView):
template_name = 'your_new_template.html'
For your reference, Django official documentation
Upvotes: 4