Reputation: 141
I have a simple project and made troubled fixing the redirection. The url is not redirecting to my statistics_detail.html. whenever i click it just adds the pk on the link but won't redirects
here is my url.py:
urlpatterns = [
url('^$', views.index, name='index'),
re_path(r'^(?P<pk>\d+)/$', views.StatisticsDetailView.as_view(), name='detail'),
url('blist/', views.StatisticListView.as_view(), name='blist'),
url('user_list', DisplayView.as_view(), name='user_list'),
url('new_user', views.new_user, name='new_user'),
url('push_user_tb', views.push_user_tb, name='push_user_tb'),
url('push_user_prod', views.push_user_prod, name='push_user_prod'),
url('st', views.display_stats_logs, name='st'),
url('today', views.display_today, name='today'),
url('balance', views.display_balance, name='balance'),
]
views.py
class StatisticsDetailView(DetailView):
context_object_name = 'statistics_details'
model = models.Statistics
template_name = 'provision/statistics_detail
here is also statistics_detail.html:
{% extends 'base.html' %}
{% block content %}
<p>Statistics</p>
<div class="container">
<table class="table">
<tr>
<th>Name</th>
<th>Mac ID</th>
<th>Hours</th>
<th>Date</th>
<th>Status</th>
</tr>
{% for clients in object_list %}
<tr>
<td>{{ clients.name }}</td>
<td>{{ clients.mac_add }}</td>
<td>{{ clients.minutes_used|cut:".0" }}</td>
<td>{{ clients.date }}</td>
<td><a href="{{clients.id}}/">{{ clients.status }}</a></td>
</tr>
{% endfor %}
</table>
It is {% now "jS F Y H:i" %}
</div>
{% endblock %}
As you can see on the screenshot below. nothing happens if i click the clients.status which supposedly redirects to statistics_detail.html
Browser URL: http://127.0.0.1:8000/prov/blist/ After Click the status it would only add http://127.0.0.1:8000/prov/blist/2146/ but doesn't work
Upvotes: 0
Views: 259
Reputation: 599470
You need a leading slash: <a href="/{{clients.id}}/">
Even better, use the {% url %}
tag rather than outputting the URL manually.
Upvotes: 3