Django错误:Reverse for '' with arguments '('',)' not found.
python 3.6,django 2.0.4开发一个网站时url匹配错误,
希望帮我指出出错地方:
NoReverseMatch at /CetTopic/
Reverse for 'personal_info' with arguments '('',)' not found. 1 pattern(s) tried: ['CetPersInfo/(?P<topic_id>\d+)
我的url:
from django.conf.urls import url
from django.urls import path
from cet46.views import personal_info
from . import views
app_name='cet46'
urlpatterns = [
url(r'^$',views.index,name='index'),
url(r'^CetTopic/$',views.topic,name='topic'),
url(r'^CetPersInfo/(?P<topic_id>\d+)$',views.personal_info,name='personal_info'),#就在这个正则表达式出问题了
]
views里面的视图函数:
def personal_info(request,topic_id):
topic = Topic.objects.get(id=topic_id)
perInfo = topic.objects.all()
context = {'perInfo': perInfo}
return render(request, 'cet46/perInfo.html', context)
模板html文件:
{% extends "cet46/base.html" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
<table width="500">
<thead>
<tr>
<th>ID</th> <th>姓名</th> <th>身份证号</th> <th>性别</th> <th>年龄</th>
<th>手机号</th> <th>学校</th> <th>住址</th>
</tr>
</thead>
<tbody>
{% for row in perInfo %}
<tr>
<td>{{ row.id }}</td>
<td>{{ row.username }}</td>
<td>{{ row.user_id }}</td>
<td>{{ row.gender }}</td>
<td>{{ row.age }}</td>
<td>{{ row.phone }}</td>
<td>{{ row.school }}</td>
<td>{{ row.addr }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
主页点击Apply CET跳转时出错:
后台的错误:
]我的url:
from django.conf.urls import url
from django.urls import path
from cet46.views import personal_info
from . import views
app_name='cet46'
urlpatterns = [
url(r'^$',views.index,name='index'),
url(r'^CetTopic/$',views.topic,name='topic'),
url(r'^CetPersInfo/(?P<topic_id>\d+)$',views.personal_info,name='personal_info'),#就在这个正则表达式出问题了
]
views里面的视图函数:
def personal_info(request,topic_id):
topic = Topic.objects.get(id=topic_id)
perInfo = topic.objects.all()
context = {'perInfo': perInfo}
return render(request, 'cet46/perInfo.html', context)
模板html文件:
{% extends "cet46/base.html" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
<table width="500">
<thead>
<tr>
<th>ID</th> <th>姓名</th> <th>身份证号</th> <th>性别</th> <th>年龄</th>
<th>手机号</th> <th>学校</th> <th>住址</th>
</tr>
</thead>
<tbody>
{% for row in perInfo %}
<tr>
<td>{{ row.id }}</td>
<td>{{ row.username }}</td>
<td>{{ row.user_id }}</td>
<td>{{ row.gender }}</td>
<td>{{ row.age }}</td>
<td>{{ row.phone }}</td>
<td>{{ row.school }}</td>
<td>{{ row.addr }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
主页点击Apply CET跳转时出错:
后台的错误:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对,就是你的url配置出了问题,尝试一下这个
from django.urls import re_path
re_path('CetPersInfo/(?P<topic_id>d+)/',views.personal_info,name='personal_info'),其实Django2.0以上的版本都在用这种格式了。
老哥你这个 NoReverseMatch at /
Reverse for 'category-list' with arguments '('',)' not found. 1 pattern(s) tried: Django问题最后是怎么解决的