Reputation: 79
everyone. Here is the problem:
I'm the 'NoReverseMatch' message when i try to enter localhost/condominio/generate
NoReverseMatch at /condominio/generate Reverse for 'generate-details' with arguments '('',)' not found. 1 pattern(s) tried: ['condominio/generate/(?P<loc_id>[^/]+)$']
Here are my code parts:
urls.py:
path('generate', views.generate, name='generate-section'),
path('generate/<str:loc_id>', views.generate_details, name='generate-details'),
views.py:
def generate(request):
loc = Locatario.objects.order_by('unidade_id')
return render(request, 'calccondominio/generate.html', context)```
def generate_details(request, loc_id):
loc = get_object_or_404(Locatario, pk=loc_id)
ctr = loc.contrato_set.get(pk=loc_id)
return render(request, 'calccondominio/generate_details.html', {'loc':loc, 'ctr':ctr})
generate.html:
{% extends 'blog/base.html' %}
{% block content %}
<div class="container">
<div class="card w-100">
<div class="card-body">
<h5 class="card-title">Unidades atualmente ocupadas:</h5>
{% for l in loc %}
<a href="{% url 'generate-details' locid.id %}">{{l.unidade}}</a>
{%endfor%}
</div>
</div>
</div>
{% endblock content %}
Thanks for your help.
Upvotes: 1
Views: 58
Reputation: 476493
The name of the object o fthe Loctario
in your template is l
, not locid</s>
, you thus should rewrite it to:
{% for l in loc %}
<a href="{% url 'generate-details' l.id %}">{{l.unidade}}</a>
{% endfor %}
You can also use the .pk
to obtain the primary key, which might be better if you perhaps later change the name of the id:
{% for l in loc %}
<a href="{% url 'generate-details' l.pk %}">{{l.unidade}}</a>
{% endfor %}
Upvotes: 1