我有一个第三方django应用程序,它有自己的网址,但它们需要一个尾随斜杠。如果有和没有斜线,我怎么能支持?
答案 0 :(得分:1)
import re
from django.conf.urls import url, include
def optional_trailing_slash(urls):
for url in urls[0].urlpatterns:
url.regex = re.compile(url.regex.pattern.replace('/$', '/?$'))
return urls
urlpatterns = [
url(r'^', optional_trailing_slash(include('third_party_app.urls'))),
]