I hope you will take a look at the strange question of whether or not the django path path will be added at the end.

starts with no slash at the end of the path

  • path ("schoolhot",xxx_funciton)
  • can only access http://127.0.0.1:8000/schoolhot
  • at this time.
< hr >

change to the end of the path with a slash

< hr >

change it to the first path above

  • path ("schoolhot",xxx_funciton)
  • visiting http://127.0.0.1:8000/schoolhot will also redirect to http://127.0.0.1:8000/schoolhot/
  • at this time.
  • visit http://127.0.0.1:8000/schoolhot/ path mismatch
  • looked at f12, which is indeed a browser redirect, not made by django
  • the solution seems to be to clear the browser cache, so you can access http://127.0.0.1:8000/schoolhot
  • .
  • feel this. It"s too bad. it"s fine if you"ve never successfully accessed a path with a slash. Once the visit is successful, it will be recorded, and later visits without a slash will be directly redirected to a slash.
May.24,2022
The redirection of

is caused by django. I remember that a setting is APPEND_SLASH , which automatically adds / to the end of the requested url. The method is redirection. I don't know exactly why it is necessary to clean the cache so that it can not be redirected. may be redirected automatically because it is a permanent redirect. However, as long as you standardize the format of url, such as requiring it to end with / , there will be no such problem.


in order to ensure the uniqueness of url, adding a slash and not adding a slash are already two url, but by default, the browser will redirect a route without a slash, so we'd better add / to the end when designing the url to ensure that it can be correctly mapped to the established route without a slash, otherwise it cannot be correctly mapped to the attempt function without a slash.

Menu