Skip to content

Commit

Permalink
Envia parametro pela URL e recupera objeto pela pk
Browse files Browse the repository at this point in the history
  • Loading branch information
brnocesar committed Nov 7, 2020
1 parent e444c74 commit e21e83f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/receitas/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="single-best-receipe-area mb-30">
<img src="{% static 'img/bg-img/foto_receita.png' %}" alt="">
<div class="receipe-content">
<a href="{% url 'receita' %}">
<a href="{% url 'receita' receita.id %}">
<h5>{{ receita.nome }}</h5>
</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/receitas/templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<!-- Nav Start -->
<div class="classynav">
<ul>
<li><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'receita' %}">Receitas</a></li>
<li><a href="#">Home</a></li>
<li><a href="{% url 'index' %}">Receitas</a></li>
</ul>

<!-- Formulario de busca -->
Expand Down
2 changes: 1 addition & 1 deletion apps/receitas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

urlpatterns = [
path('', views.index, name='index'),
path('receita', views.receita, name='receita')
path('<int:receita_id>', views.receita, name='receita')
]
6 changes: 3 additions & 3 deletions apps/receitas/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from .models import Receita

def index(request):
return render(request, 'index.html', {'receitas': Receita.objects.all()})

def receita(request):
return render(request, 'receita.html')
def receita(request, receita_id):
return render(request, 'receita.html', {'receita': get_object_or_404(Receita, pk=receita_id)})

0 comments on commit e21e83f

Please sign in to comment.