Why django urls end with a slash?

前端 未结 4 480
半阙折子戏
半阙折子戏 2020-12-14 01:55

Django official documentation and other tutorials on the web always use a trailing slash at the end of url. ex:

url(r\'^accounts/login/\', views.login)  # lo         


        
4条回答
  •  盖世英雄少女心
    2020-12-14 02:16

    "URLs should be beautiful"!!! I want to be able to control URLs. It's nothing nice when everything is about to be overwritten. Under circumstances, I make a redirect loop which is not funny.

    from django.http import HttpResponseRedirect as rdrct
    
    url(r'^sitemap.xml$', 'my_app.views.custom_sm'),
    
    url(r'^sitemap.xml/$', lambda x: rdrct('/sitemap.xml')),
    

提交回复
热议问题