Article From:https://segmentfault.com/q/1010000014740157
Question:

python 3.6,django 2.0.4URL matching errors when developing a web site,
I hope to help me point out the mistakes.
NoReverseMatch at /CetTopic/

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

My 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'),#It's a problem in this regular expression.]

viewsThe view function inside:

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)

Template HTML file:

{% 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>Name < /th> < th> ID card number < /th> < th> sex < /th> < < age;< th> mobile phone number < /th> < th> school < /th> < th> address < 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&gT;< /table>< /div>< /body>< /html>

There is an error when the home page hits Apply CET.

Backstage error:

Answer 0:

Yes, your URL configuration is out of order. Try this.
from django.urls import re_path
re_path(‘CetPersInfo/(?P<topic_id>d+)/’,views.personal_info,name=’personal_info’),In fact, more than Django2.0 versions are in this format.

Similar Posts:

One Reply to “Django error: Reverse for ” with arguments’ (‘,’), not found.”

Leave a Reply

Your email address will not be published. Required fields are marked *