Python Web development-flask URL with slash/And no slash/difference

Source: Internet
Author: User
URL with slash and no slash in flask

When routing configuration via flask, there is a detail that is the same URL, with "/" and No "/" difference.

To illustrate:

For example, there is a URL named "/url"

First define both URLs, one with "/", One Without "/", the following code:

@app. Route ("/url")
def urlwithout ():
return "url with out/"


@app. Route ("/url/")
def Urlwith ():
return "url with/"

To access/url, the effect is as follows:

Access the/url/effect as follows:

And then/url this definition, and again visit/url, found to jump to/url/this address

If you comment out the definition of/url/, keep the definition of/url, visit/url/again, find the 404 error

Conclusion: When a URL with a slash and a slash is present, the two URLs are independent of each other to handle their own logic.

When a URL with a slash exists and the URL without a slash does not exist, the URL with the slash and the URL without the slash can be accessed at the same time, but the returned result is the same.

When the URL with the slash does not exist, the URL without the slash is present, the URL with the slash returns 404, and the URL without the slash is normally accessed.

Python Web development-flask URL with slash/And no slash/difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.