index.html
{% block allposts %}
{% endblock %}
Culture • Jul 5th '22
What is the son of Football Coach John Gruden, Deuce Gruden doing Now?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Distinctio placeat exercitationem magni voluptates dolore. Tenetur fugiat voluptates quas, nobis error deserunt aliquam temporibus sapiente, laudantium dolorum itaque libero eos deleniti?

Wade Warren
{% block content %}
{% endblock %}
Вот содержимое политического.html, которое я пытаюсь визуализировать
{% extends 'index.html' %}
{% block content %}
{% for politics in politics %}
{{post.category}} • {{post.created_at}}
{{post.title}}
Ole Pundit
{{post.body|truncatewords:75}}
{% endfor %}
{% endblock %}
И allposts.html
{% extends 'index.html' %}
{% block allposts %}
{% for post in posts %}
{{post.category}} • {{post.created_at}}
{{post.title}}
{{post.body|truncatewords:75}}
OlePundit
{% endfor %}
{% endblock %}
Вот мой файл models.py
from django.db import models
from datetime import datetime
from django_resized import ResizedImageField
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=100)
body = models.CharField(max_length=1000000)
created_at = models.DateTimeField(default=datetime.now, blank = True)
image = ResizedImageField(size=[250, 200], upload_to='img')
category = models.CharField(max_length=100)
И мои URL-адреса
from django.urls import path
from . import views
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
urlpatterns= [
path('', views.index, name='index'),
path('/', views.post, name='post'),
path('political', views.political, name='political'),
path('allposts', views.allposts, name='allposts')
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Views.py
from django.shortcuts import render
from .models import Post
from django.views.generic import DetailView
# Create your views here.
def index(request):
return render(request, 'blog/index.html')
def allposts(request):
posts = Post.objects.all()
return render(request, 'blog/allposts.html', {'posts':posts})
def political(request):
politics = Post.objects.filter(category__contains='politics')
return render(request, 'blog/political.html', {'politics':politics})
def post(request, pk):
posts = Post.objects.get(id=pk)
return render(request, 'blog/posts.html', {'posts':posts})
Подробнее здесь: https://stackoverflow.com/questions/725 ... -rendering
Мобильная версия