【解决错误】Non-reversible reg-exp portion: '(?i'

在将Django升级到2.1后,运行 Django 自带后台后,或 使用 redirect 方法,就一直报错:Non-reversible reg-exp portion: '(?i'。

错误一

Django 2.X不再支持的URL正则写法:

url(r'(?i)^a/$', view.fun1)

url(r'^(?i)a/$', view.fun1)

应该改为:

url(r'^a/$(?i)', view.fun1)

同时也建议 Django2.+中,建议不要再使用 url,而改为 path 或 re_path。

--------------------------------------------------------------

错误二

使用 django.shortcuts.redirect 报错:Non-reversible reg-exp portion: '(?i':
使用 django.http.HttpResponseRedirect 来代替 django.shortcuts.redirect
原文地址:https://www.cnblogs.com/xunziji/p/11567250.html