pycharm django正则表达式报错
Django使用正则表达式匹配url时提示
WARNINGS:?: (2_0.W001) Your URL pattern '^$/' [name='index'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
错误
解决:
旧版本中正则表达式匹配url写法为:
path(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html',views.detail)
而新版本不需要写r和^等符号,直接写要匹配的url即可,
但如果要进行正则表达式匹配url时需要导入re_path模块
即 from django.urls import re_path
正则表达式:
re_path('detail-(?P<nid>\d+)-(?P<uid>\d+).html',views.detail)