Flask is the example of a video document run error: if Self.url_rule and '. ' In Self.url_rule.endpoint__flask

Source: Internet
Author: User

Example Address: http://docs.jinkan.org/docs/flask/views.html

The author wrote a test example according to the document, in the browser access http://127.0.0.1:5000/user/error: If Self.url_rule and '. ' In Self.url_rule.endpoint.

The test example code is as follows:


flask
render_templateView app = Flask (
__name__)

 Showusers (View):
    dispatch_request (self):
        render_template (' test.html ')

App.add_url_rule ('/user/', Showusers.as_view (' show_users '))

__name__ = = ' __main__ ':
    app.run ( )

Workaround:

According to the error information, view app.add_url_rule related documents, parameters endpoint general and view function names are the same, the code is modified as follows:


flask
render_templateView app = Flask (
__name__)

 Showusers (View):
    dispatch_request (self):
        render_template (' test.html ')

App.add_url_rule ('/user/', ' show_users ', Showusers.as_view (' show_users '))

__name__ = = ' __main__ ':
    App.run ()

http://127.0.0.1:5000/user/is normal in browser access.

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.