feat: article page
This commit is contained in:
@@ -29,6 +29,11 @@ a {
|
|||||||
padding-right: 15px;
|
padding-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.one-post:hover {
|
||||||
|
background: #334661;
|
||||||
|
transition: .3s ease-in;
|
||||||
|
}
|
||||||
|
|
||||||
.article-created-date {
|
.article-created-date {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
@@ -38,3 +43,17 @@ a {
|
|||||||
gap: 20px;
|
gap: 20px;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-link {
|
||||||
|
text-decoration: none;
|
||||||
|
color: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-meta {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-header {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
@@ -15,14 +15,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="archive">
|
<div class="archive">
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div class="one-post">
|
<a class="post-link" href="/article/{{ post.id }}">
|
||||||
<h2 class="post-title">{{ post.title }}</h2>
|
<div class="one-post">
|
||||||
<div class="article-info">
|
<h2 class="post-title">{{ post.title }}</h2>
|
||||||
<strong class="article-author">{{ post.author.first_name }}</strong>
|
<div class="article-info">
|
||||||
<div class="article-created-date">{{ post.created_date }}</div>
|
<strong class="article-author">{{ post.author.first_name }}</strong>
|
||||||
|
<div class="article-created-date">{{ post.created_date }}</div>
|
||||||
|
</div>
|
||||||
|
<p class="article-text">{{ post.get_excerpt }}</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="article-text">{{ post.get_excerpt }}</p>
|
</a>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
29
articles/templates/article.html
Normal file
29
articles/templates/article.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{{ post.title }}</title>
|
||||||
|
{% load static %}
|
||||||
|
<link rel="stylesheet" href="{% static 'index.css' %}">
|
||||||
|
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<img src="{% static 'logo.svg' %}" />
|
||||||
|
<h1>Всё про IT</h1>
|
||||||
|
</div>
|
||||||
|
<h1 class="article-header">{{ post.title }}</h1>
|
||||||
|
|
||||||
|
<div class="article-meta">
|
||||||
|
<p>{{ post.author.first_name }}</p>
|
||||||
|
<p>{{ post.created_date }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ post.text|linebreaks }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><a href="/">← Назад к списку статей</a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
from .models import Article
|
from .models import Article
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.http import Http404
|
||||||
|
|
||||||
def archive(request):
|
def archive(request):
|
||||||
return render(request, 'archive.html', {"posts": Article.objects.all()})
|
return render(request, 'archive.html', {"posts": Article.objects.all()})
|
||||||
|
|
||||||
|
def get_article(request, article_id):
|
||||||
|
try:
|
||||||
|
post = Article.objects.get(id=article_id)
|
||||||
|
return render(request, 'article.html', {"post": post})
|
||||||
|
except Article.DoesNotExist:
|
||||||
|
raise Http404
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, re_path
|
||||||
from articles import views
|
from articles import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('', views.archive),
|
path('', views.archive),
|
||||||
|
re_path(r'^article/(?P<article_id>\d+)$', views.get_article, name='get_article'),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user