feat: article page
This commit is contained in:
@@ -29,6 +29,11 @@ a {
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.one-post:hover {
|
||||
background: #334661;
|
||||
transition: .3s ease-in;
|
||||
}
|
||||
|
||||
.article-created-date {
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -37,4 +42,18 @@ a {
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
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 class="archive">
|
||||
{% for post in posts %}
|
||||
<div class="one-post">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
<div class="article-info">
|
||||
<strong class="article-author">{{ post.author.first_name }}</strong>
|
||||
<div class="article-created-date">{{ post.created_date }}</div>
|
||||
<a class="post-link" href="/article/{{ post.id }}">
|
||||
<div class="one-post">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
<div class="article-info">
|
||||
<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>
|
||||
<p class="article-text">{{ post.get_excerpt }}</p>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</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 django.shortcuts import render
|
||||
from django.http import Http404
|
||||
|
||||
def archive(request):
|
||||
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'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
from articles import views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', views.archive),
|
||||
re_path(r'^article/(?P<article_id>\d+)$', views.get_article, name='get_article'),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user