This commit is contained in:
Allecks 2022-10-04 16:11:01 +03:00
parent 4ada78aa74
commit 4439bb6d46
3 changed files with 24 additions and 6 deletions

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta 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>

View file

@ -1,9 +1,7 @@
from django.http import HttpResponse from django.shortcuts import render
from .models import Bb from .models import Bb
def index(request): def index(request):
s = 'Список объявлений \r\n\r\n\r\n' bbs = Bb.objects.order_by('-published')
for bb in Bb.objects.order_by('-published'): return render(request, 'index.html', {'bbs': bbs})
s += bb.title + '\r\n' + bb.content + '\r\n\r\n'
return HttpResponse(s, content_type = 'text/plain; charset=utf-8')

View file

@ -10,6 +10,7 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/ https://docs.djangoproject.com/en/4.1/ref/settings/
""" """
import os
from pathlib import Path from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -55,7 +56,9 @@ ROOT_URLCONF = 'samplesite.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [
os.path.join(BASE_DIR, 'bboard/templates'),
],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [