TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
<!DOCTYPE html>
<html lang="ru">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>Главная - Доска объявлений</title>
</head>
<body>
<h1>Объявления</h1>
{% for bb in bbs %}
<div>
<h2>{{ bb.title }}</h2>
<p>{{ bb.content }}</p>
<p>{{ bb.published|date:"d.m.Y. H:i:s"}}</p>
</div>
{% endfor %}
</body>
</html>
{% for bb in bbs %}
...
{% endfor %}
{{ bb.title }}
<p>{{ bb.published|date:"d.m.Y. H:i:s"}}</p>
from .models import Bb
from django.shortcuts import render
def index(request):
bbs = Bb.objects.order_by('-published')
return render(request, "btest/index.html", {'bbs': bbs})
from django.contrib import admin
from django.urls import path, include
from btest import views
urlpatterns = [
path('', views.index),
path('admin/', admin.site.urls),
]
from .models import Bb
from django.template.response import TemplateResponse
def index(request):
bbs = Bb.objects.order_by('-published')
return TemplateResponse(request, "btest/index.html", {'bbs': bbs})