【发布时间】:2019-10-21 17:55:12
【问题描述】:
我有一个简单的项目,在修复重定向时遇到了麻烦。 该 url 没有重定向到我的 statistics_detail.html。每当我点击它时,它只会在链接上添加 pk,但不会重定向
这是我的 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
这里也是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 %}
正如您在下面的屏幕截图中看到的那样。如果我点击应该重定向到 statistics_detail.html 的clients.status,什么也不会发生
浏览器网址:http://127.0.0.1:8000/prov/blist/ 点击状态后只会添加http://127.0.0.1:8000/prov/blist/2146/但不起作用
【问题讨论】:
-
仍然没有工作@BearBrown
标签: django python-3.x detailview