Python Flask Blueprint Blueprint

Source: Internet
Author: User

1. Directory structure

2. manage.py similar to Django in manage

Import Fcrm if __name__ ' __main__ ' :    fcrm.app.run (Port=8001)

3. Fcrm the following __init__.py file

 fromFlaskImportFlask from. viewsImportAccount#Import the account.py module under the Fcrm.views directory, from. viewsImportOrder#Import the order.py module under the Fcrm.views directory,app= Flask (__name__)#using blueprints, the App.route () mode is still available, paying attention to the problem of routing duplicationapp.register_blueprint (Account.account)#Register the Blueprint object account in the Views module with the appApp.register_blueprint (Order.order)#Register the Blueprint object order in the Views module with the app

3. Account and Order module under the Fcrm.view directory

 fromFlaskImportBlueprintorder= Blueprint ('Order',__name__)#creates a Blueprint object. The first parameter can be seen as the name of the Blueprint object                                         #in one app, the name cannot be duplicated with the rest of the Blueprint object name                                         #The second parameter, __name__, is used as an initialization@order. Route ('/order')#use a Blueprint object as an ' app 'deflogin ():return 'Order'
 from  flask import   Blueprint,render_templateaccount  = Blueprint ("  account  " , __name__    " /login  "  )  def   login ():  #   return ' Login '  return  render_ Template ( " login.html   ) 
Summary ideas:     1. mange.py file runs, first run the Code    2. init file in the __init__.py file below the Fcrm directory into theflask and the py file    3 under the View directory . Then Init creates the Flask    object 4. Register the module file below the views directory with the Blueprint    object 5. mange.py finally runs the Code app object in init

Python Flask Blueprint Blueprint

Related Article

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.