NoReverseMatch: Reverse for 'complete' with arguments '(1,)' not found. 1 pattern(s) tried: ['complete/']

后端 未结 3 1357
小蘑菇
小蘑菇 2021-01-22 10:34

urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
url(\'\', views.index, name= \'index\'),
url(\'add\', views.addTodo, name =\'add\')         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 11:24

    Your regex expression is wrong:

    Instead of this:

    url('complete/', views.completeTodo, name='complete'),
    

    try this:

    url(r'^complete/(?P\d+)$', views.completeTodo, name='complete'),
    

    Or in case you want to use path

    path('complete/', views.completeTodo, name='complete'),
    

    EDIT

    Since you're using Django 1.*, you can't use path() The correct way to set up all your URLs is with url regex expressions

    Note

    '^': The match must start at the beginning of the string or line.

    '$': The match must occur at the end of the string

    '\d+': Match all digits

    The r at the beginning stands for regex

    url(r'^$', views.index, name= 'index'),
    url(r'^add$', views.addTodo, name ='add'),
    url(r'^complete/(?P\d+)$', views.completeTodo, name='complete'),
    url(r'^deletecomplete$', views.deleteCompleted, name='deletecomplete'),
    url(r'^deleteall$', views.deleteAll, name='deleteall')
    

提交回复
热议问题