W
W
Werdjill2020-05-03 15:54:39
Django
Werdjill, 2020-05-03 15:54:39

TemplateDoesNotExist at /blog/ error, how to solve?

Code Views
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from .models import *

def posts_wall(request):
    object_list = Post.objects.all()
    paginator = Paginator(object_list, 5)
    page = request.GET.get('page')
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    return render(request, 'post/list.html', {'page': page, 'posts' : posts})

def post_detail(request, year, month, day, post):
    post = get_object_or_404(Post, slug = post, status = 'published', published__year = year,
        published__month = month, published__day = day)
    return render(request, 'post/detail.html', {'post' : post})


Code templates/blog/base.html
{% load static %}
<!DOCTYPE html>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<html>
    <head>
        <title>{% block title %}{% endblock %}</title>
        <link href="{% static "css/blog.css" %}" rel="stylesheet">
        <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
          <a class="navbar-brand" href="{%url 'blog:posts' %}">Блогиyс</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>

          <div class="collapse navbar-collapse" id="navbarColor01">
            <ul class="navbar-nav mr-auto">
              <li class="nav-item active">
                <a class="nav-link" href="{%url 'blog:posts' %}">Главная<span class="sr-only">(current)</span></a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Обо мне</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Контакты</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Мои социальные сети</a>
              </li>
            </ul>
          </div>
        </nav>
    </head>
    <body>
        <div id="content">
            {% block content %}{% endblock %}
        </div>
    </body>
</html>


templates/blog/pagination code
<div class="pagination">
    <span class="step-links">
        {% if page.has_previous %}
            <a href="?page={{page.previous_page_number}}">Previous</a>
        {% endif %}
        <span class="current">
            Page {{ page.number }} of {{ page.paginator.num_pages }}.
        </span>
        {% if page.has_next %}
            <a href="?page={{ page.next_page_number }}">Next</a>
        {% endif %}
    </span>
</div>


Code templates/post/list.html
{% extends "blog/base.html" %}
{% block title %}My Blog{% endblock %}
{% block content %}
    <h1 align = 'center'>My Blog</h1>
{% for post in posts %}
<h2>
    <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
</h2>
<p class="date">Published {{ post.publish }} by {{ post.author }}</p>
{{ post.body|truncatewords:30|linebreaks }}
{% endfor %}
    {% include "pagination.html" with page=posts %}
{% endblock %}


Mistake
TemplateDoesNotExist at /blog/


Please help, if you need anything else, you can throw it off, thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-03
@galaxy

Does the post/detail.html template exist in nature?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question