在将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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
相关资源
相似解决方案