Criando urls dinâmicas no Django URL Dispatcher, view e template

This commit is contained in:
Luiz Otávio
2023-04-27 09:19:51 -03:00
parent b03360b1f8
commit 30a5ee9381
3 changed files with 23 additions and 1 deletions

View File

@@ -1,6 +1,10 @@
<article class="post">
<header>
<h2 class="post__title">{{ post.title }}</h2>
<h2 class="post__title">
<a href="{% url 'blog:post' post.id %}">
{{ post.title }}
</a>
</h2>
</header>
<div class="post__body">{{ post.body }}</div>
</article>

View File

@@ -4,7 +4,10 @@ from django.urls import path
app_name = 'blog'
# blog/
# Django URLs:
# https://docs.djangoproject.com/en/4.2/topics/http/urls/
urlpatterns = [
path('', views.blog, name='home'),
path('post/<int:id>', views.post, name='post'),
path('exemplo/', views.exemplo, name='exemplo'),
]

View File

@@ -17,6 +17,21 @@ def blog(request):
)
def post(request, id):
print('post', id)
context = {
# 'text': 'Olá blog',
'posts': posts
}
return render(
request,
'blog/index.html',
context
)
def exemplo(request):
print('exemplo')