【解決錯誤】Non-reversible reg-exp portion: '(?i'

在將Django升級到2.1後,運行 Django 自帶後臺後,或 使用 redirect 方法,就一直報錯:Non-reversible reg-exp portion: '(?i'。django

 

錯誤一url

Django 2.X再也不支持的URL正則寫法:spa

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

code

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

 

應該改成:blog

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

 

同時也建議 Django2.+中,建議不要再使用 url,而改成 path 或 re_path。io

--------------------------------------------------------------class

錯誤二後臺

使用 django.shortcuts.redirect 報錯:Non-reversible reg-exp portion: '(?i':
使用 django.http.HttpResponseRedirect 來代替 django.shortcuts.redirect
相關文章
相關標籤/搜索