鍍金池/ 問(wèn)答/Python  網(wǎng)絡(luò)安全  HTML/ Django錯(cuò)誤:Reverse for '' with arguments '

Django錯(cuò)誤:Reverse for '' with arguments '('',)' not found.

python 3.6,django 2.0.4開(kāi)發(fā)一個(gè)網(wǎng)站時(shí)url匹配錯(cuò)誤,
希望幫我指出出錯(cuò)地方:
NoReverseMatch at /CetTopic/

Reverse for 'personal_info' with arguments '('',)' not found. 1 pattern(s) tried: ['CetPersInfo/(?P<topic_id>\d+)$']

clipboard.png

我的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'),#就在這個(gè)正則表達(dá)式出問(wèn)題了
]

views里面的視圖函數(shù):

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>身份證號(hào)</th> <th>性別</th> <th>年齡</th>
                <th>手機(jī)號(hào)</th> <th>學(xué)校</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>

clipboard.png

主頁(yè)點(diǎn)擊Apply CET跳轉(zhuǎn)時(shí)出錯(cuò):

clipboard.png

后臺(tái)的錯(cuò)誤:

clipboard.png

回答
編輯回答
萌小萌

對(duì),就是你的url配置出了問(wèn)題,嘗試一下這個(gè)
from django.urls import re_path
re_path('CetPersInfo/(?P<topic_id>d+)/',views.personal_info,name='personal_info'),其實(shí)Django2.0以上的版本都在用這種格式了。

2017年1月18日 00:32