Configurando um post único no template post.html
This commit is contained in:
@@ -31,7 +31,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 600px) {
|
@media (min-width: 600px) {
|
||||||
.content {
|
.content:not(:has(.single-post)) {
|
||||||
grid-template-columns: repeat(auto-fill, minmax(32rem, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(32rem, 1fr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
aula207_ola_django/blog/templates/blog/post.html
Normal file
16
aula207_ola_django/blog/templates/blog/post.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{% extends 'global/base.html' %}
|
||||||
|
|
||||||
|
{% block texto %} {{ text }} {% endblock texto %}
|
||||||
|
|
||||||
|
{% block posts %}
|
||||||
|
<article class="post single-post">
|
||||||
|
<header>
|
||||||
|
<h1 class="post__title">
|
||||||
|
<a href="{% url 'blog:post' post.id %}">
|
||||||
|
{{ post.title }}
|
||||||
|
</a>
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
<div class="post__body">{{ post.body }}</div>
|
||||||
|
</article>
|
||||||
|
{% endblock posts %}
|
||||||
@@ -8,6 +8,6 @@ app_name = 'blog'
|
|||||||
# https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
# https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.blog, name='home'),
|
path('', views.blog, name='home'),
|
||||||
path('<int:id>/', views.post, name='post'),
|
path('<int:post_id>/', views.post, name='post'),
|
||||||
path('exemplo/', views.exemplo, name='exemplo'),
|
path('exemplo/', views.exemplo, name='exemplo'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from blog.data import posts
|
from blog.data import posts
|
||||||
|
from django.http import HttpRequest
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
@@ -17,17 +20,26 @@ def blog(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def post(request, id):
|
def post(request: HttpRequest, post_id: int):
|
||||||
print('post', id)
|
found_post: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
for post in posts:
|
||||||
|
if post['id'] == post_id:
|
||||||
|
found_post = post
|
||||||
|
break
|
||||||
|
|
||||||
|
if found_post is None:
|
||||||
|
raise Exception('Post não existe.')
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
# 'text': 'Olá blog',
|
# 'text': 'Olá blog',
|
||||||
'posts': posts
|
'post': found_post,
|
||||||
|
'title': found_post['title'] + ' - ',
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'blog/index.html',
|
'blog/post.html',
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user