1👍
✅
You should iterate over the candidates
QuerySet instead of the lista2
list. Then you can do it like this:
{% for candidate in candidates %}
<p class="tr">
<a href="{% url 'candidate_detail' candidate.pk %}">{{ candidate }}</a>
</p>
{% endfor %}
0👍
Replace href
to the following:
{% load staticfiles %}
{% load mathfilters %}
<!DOCTYPE html>
<html>
<head>
<title>Lista de candidatos</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="https://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link href="{% static 'css/app.css' %}" rel="stylesheet">
</head>
<body>
<h1 class="h1t">Lista de Candidatos</h1>
{% for l in lista2 %}
<p class="tr"><a href="{% url 'candidate_detail' post.pk %}">{{l}}</a></p>
{% endfor %}
</body>
</html>
In Django, when referencing a view using url
, you need to use the name
attribute that you have defined for it in the urls.py
Source:stackexchange.com