<h1> Message board homepage </h1>
{% for post in post_list %}
<li>{{post.text}}</li>
{%endfor%}
First, the reference to post_list.html is a reference to the default view name for a ViewList. If it can’t find the view named in the template_name attribute of the class, it will try to find that default view. So the root cause here is that it’s not finding your home.html template.
Now, note that the tutorial has:
In your text editor, create a new file called templates/home.html
So the tutorial is written to have you put your template directly in the templates directory, not within a subdirectory for the app.
You can either change the location of your home.html template or change your reference in the template_name attribute to match its actual location.
Ahh, I think I see it now.
The TEMPLATES DIRS setting is already relative to your project root, it’s not an absolute path. You should not prepend BASE_DIR on to the DIRS entries.
(Or to be more precise, it’s generally defined that way. It can be absolute, but then in this case, you’d want to verify that the entry being created is accurate.)
Side note: Additionally, if you’re going to store and use templates in apps, you may also want to set the APP_DIRS setting to true. In the “common case”, DIRS is set to a project-level templates directory while the APP_DIRS setting is used to specify that templates could exist in the individual app_dir/templates directory.
Still same problem is coming it is searching for post_list.html.
I’ve changed the templates from app to project.
My Files structure:
main_prj,post,templates,sqlite,manage.py
templates structure (templates → home.html)
settings.py
'DIRS' : [BASE_DIR/ "templates"],
Error:
django.template.exceptions.TemplateDoesNotExist: post/post_list.html
What to do now ?
post [views.py]
from django.shortcuts import render
from django.views.generic import ListView
from .models import Post
# Create your views here.
class HomePage(ListView):
model = Post
template = "home.html"