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