0

I have 2 buttons and when I click on one of them I want to be redirected to a new html page, using the id as a parameter.

My URLs

urlpatterns = [
    path('', admin.site.urls, name ='home'),
    path('dpo/imprimir/aprovado/<int:id>/',Aprovado, name ='aprovado'),
    path('dpo/imprimir/reprovado/<int:id>/',Reprovado, name ='reprovado'),
    ]

My Template

{% load i18n admin_urls %}
{% block object-tools-items %}
<li>
    <a href="/dpo/imprimir/aprovado/{{instance.id}}">{% trans "Aprovado" %}</a>
</li>
<li>

    <a href="/dpo/imprimir/reprovado/{{instance.id}}">{% trans "Não aprovado" %}
</li>
{% endblock %}

My views

from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import render_to_response
from .models import Projeto


def Aprovado(request, id):
        obj = Projeto.objects.get(id=id)
        context = {
                "object": obj
        }
        return render(request, "dpo/imprimir/aprovado.html", context)

def Reprovado(request, id):
        obj = Projeto.objects.get(id=id)
        context = {
                "object": obj
        }
        return render(request, "dpo/imprimir/reprovado.html", context)

I think I'm doing this the wrong way.

Pedro Mariz
  • 151
  • 2
  • 20

2 Answers2

2

Try this

<a href="{% url 'aprovado' object.id %}">{% trans "Aprovado" %}</a>
<a href="{% url 'reprovado' object.id %}">{% trans "Não aprovado" %}
shafik
  • 6,098
  • 5
  • 32
  • 50
0

Since the object instance name is given as "object" in the context, you need to refer it in the template, like

<a href="/dpo/imprimir/aprovado/{{object.id}}">{% trans "Aprovado" %}</a>
art
  • 1,358
  • 1
  • 10
  • 24