Why django urls end with a slash?

Django's official documentation and other online tutorials always use a slash at the end of a URL. eg:

url(r'^accounts/login/', views.login)  # login view in turn calls login.html

# instead of

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

Since this accountsis a directory and login (login.html)this is a file, we should not use a second URL? It will also make the parameters GETmore structured:

accounts/login?name='abc'  # login is a file that is accepting parameters
vs.
accounts/login/?name='abc' # login directory (maybe index) is accepting parameters??
+11
source share
4 answers

One of the main philosophies of Djangos - URLs should be beautiful.

, URL-, accounts/detail?name='abc' accounts/detail/abc/. URL. URL . ( rel=canonical) SEO.

( about.html), about.html users/awesomeUser

users/awesomeUser users/awesomeUser/ ,

  1. users/awesomeUser, users/about.html ,

  2. users/awesomeUser/, users/awesomeUser/about.html

  • child family/parent/ family/parent/child.
  • child family/parent - family/child.

Django " URL" :

, foo.com/bar foo.com/bar/ - URL-, ( -) . Django "" URL, .

APPEND_SLASH. (APPEND_SLASH URL)

?

  1. django URL , , Django user/awesomeUser user/awesomeUser/.
  2. HTTP, GET, URL ( - REST API).

POST/PUT/PATCH/DELETE rest_framework APPEND_SLASH=False trailing_slash=False , ( Routers). , . append slashes .

, .

+16

. django -, , , , , "" URL-, accounts/loginreset?id=alkfjahgouasfjvn25jk1k25

, .

+1

, APPEND_SLASH

URL-, URL-.

django, SEO, URL-.

, , , , .

+1
source

"URL must be beautiful" !!! I want to be able to control the URL. Nothing nice when everything is going to be rewritten. Under certain circumstances, I do 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')),
0
source

Source: https://habr.com/ru/post/1014946/


All Articles