正则表达式与给定模式不匹配

时间:2019-07-04 19:02:01

标签: django

regular expression not matching.
The current path, attendance/B-2019-07-05, didn't match any of these.
从django.urls导入路径

re_path     从django.contrib.auth导入视图作为auth_views     来自。将视图作为视图导入

urlpatterns = [
    path('plan/', views.plan_view, name='plan_name'),
    path('journey/', views.Journey_view),
    path('attendance/', views.attendance_view),
    re_path(r'^attendance/(?P<date>\[AB]-\d{4}-\d{2}-\d{2})/$', views.index, name='update_data'),
    path('login/', views.user_login, name='login',),
    path('', views.user_logout, name='logout_now'),
    path('logout/', views.logout_view, name='logout_name'),
    path('register/', views.register),
    path('attendance/', views.attendance_view, name='attendance'),  


    path('passwordchange/', views.PasswordChangeView, name='change_password'),
    path('passwordchangedone/', views.PasswordChangeDoneView, name='password_change_done'),
    # path('attendance/', views.attendance_view),  
    re_path(r'^export/csv/$', views.export_report_csv, name='export_report_csv'),
]

1 个答案:

答案 0 :(得分:0)

您的re_path包含反斜杠:

r'^attendance/(?P<date>\[AB]-\d{4}-\d{2}-\d{2})/$'
#                      ^

您应该删除此代码,因为通过转义[,您可以指定用户*从字面上写[,以便它接受URL attendance/[AB]-2019-07-04/

re_path应该看起来像:

re_path(r'^attendance/(?P<date>[AB]-\d{4}-\d{2}-\d{2})/$', views.index, name='update_data'),