In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "the use of the Python_Flask converter and the method of customizing the converter". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Directory default converter custom converter definition method 1. Create a converter class and save the regular expression 2. Inform the Flask application 3. Define the use where the converter is used
Default converter
From flask import Flaskapp = Flask (_ _ name__) # / user/123@app.route ('/ users/') def get_users_data (user_id): return 'get user {}' .format (user_id)
This 123 is the string str
From flask import Flaskapp = Flask (_ _ name__) # / user/123@app.route ('/ users/') def get_users_data (user_id): return 'get user {}' .format (user_id)
Custom converter definition method
The custom converter mainly takes three steps
1. Create a converter class to save the regular expression when matching
From werkzeug.routing import BaseConverterclass MobileConverter (BaseConverter): "Mobile phone number format"regex = rang 1 [3-9]\ d {9}]'
Note that the regex name is fixed
two。 Inform the Flask application of the custom converter
App = Flask (_ _ name__) # add the custom converter to the converter dictionary and specify that the converter is used with the name: mobileapp.url_map.converters ['mobile'] = MobileConverter
3. Define the use where the converter is used
@ app.route ('/ sms_codes/') def send_sms_code (mob_num): return 'send sms code to {}' .format (mob_num) "the use of the Python_Flask converter and how to customize the converter" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.