当前位置:网站首页>Configure flask
Configure flask
2022-07-26 07:19:00 【ZXY_ lucky】
1. create a file

2. Use django Open file

2.2 Choose the path

3. Configure virtual environment
First step :
The second step :

4. Install the required package
First step : Copy files from the root directory 
The second step :pip install -r file name install
5. To configure app
5.1 To configure create_app
First step : Created in the root directory create_app file
from flask import Flask
from views.order import order_bp
from models.model import db
def create_app(config):
flask_app = Flask(__name__)
flask_app.config.from_object(config)
# Registered blueprint
flask_app.register_blueprint(order_bp)
db.init_app(flask_app)
return flask_app
5.2 Configure default file
establish settings Folder , establish config file
class DefaultConfig:
SECRET_KEY = 'ashdvbjsvsvbsivksvskd'
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:[email protected]:3306/homework'
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = True
JSON_AS_ASCII = False
5.3 To configure app
First step : Created in the root directory app file
notes :: Cross domain configuration is required for front and rear end joint commissioning
from create_app import create_app
from settings.config import DefaultConfig
from flask_cors import CORS
app = create_app(DefaultConfig)
cors = CORS(app)
6. Configuration blueprint
First step : Create a folder at the root
The second step : create a file
6.1 Configuration blueprint
from flask import Blueprint
order_bp = Blueprint('order_bp',__name__,url_prefix='/order')
6.2 Registered blueprint
stay create_app Registered in the
flask_app.register_blueprint(order_bp)
6.3 The configuration view
Remember to configure the route
from flask_restful import Api,Resource,reqparse
order_bp = Blueprint('order_bp',__name__,url_prefix='/order')
api = Api(order_bp)
class HospitalView(Resource):
def get(self):
return '111'
api.add_resource(HospitalView,'/list')
7. Configuration database
7.1 establish model file
establish models Folder , create a file
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
7.2 To configure db
stay create_app file
from flask import Flask
from views.order import order_bp
from models.model import db
def create_app(config):
flask_app = Flask(__name__)
flask_app.config.from_object(config)
# Registered blueprint
flask_app.register_blueprint(order_bp)
db.init_app(flask_app)
return flask_app
7.3 Create table
stay model file
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
# The hospital
class Host(db.Model):
id = db.Column(db.Integer,primary_key=True,autoincrement=True,comment=' The hospital ID')
name = db.Column(db.String(32),comment=' Hospital name ')
img = db.Column(db.String(256),comment=' picture ')
phone = db.Column(db.String(11), comment=' Telephone ')
adr = db.Column(db.String(64), comment=' Address ')
meals = db.relationship('Meal',backref='host')
7.4 To configure manage file
Created in the root directory manage file
from flask_script import Manager
from app import app
from flask_migrate import Migrate,MigrateCommand
from models.model import db
manage = Manager(app)
migrate = Migrate(app,db)
manage.add_command('db',MigrateCommand)
if __name__ == '__main__':
manage.run()
7.5 Generate migration execute migration
python manage.py db init # Initialize database
python manage.py db migrate # Generate migration
python manage.py db upgrade # Perform the migration
边栏推荐
- NFT数字藏品开发:数字藏品助力企业发展
- Opencv learning drawing shapes and text
- Uncover the mystery of cloud native data management: operation level
- Do you want to restart the database to replace the license?
- Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
- Typora免费版下载安装
- 6、组合数据类型
- NPM command
- 成为 Apache 贡献者,So easy!
- How can man Bang write a new footnote to the value of the industry's first social responsibility report?
猜你喜欢

4. Data integrity

Opencv learn read images videos and webcams

金融任务实例实时、离线跑批Apache DolphinScheduler在新网银行的三大场景与五大优化

Drools (3): drools basic syntax (1)

Hands on practice - teach you how to make an intelligent fish tank with STM32

MySQL installation tutorial - hands on installation

Yolov6 target detection practice: training your own data set (video tutorial)

数据平台调度升级改造 | 从Azkaban 平滑过度到 Apache DolphinScheduler 的操作实践

404 page best practices to improve user experience

Opencv learning drawing shapes and text
随机推荐
NFT digital collection system development: how enterprises develop their own digital collection platform
[QT] detailed explanation of *.pro, *.pri, *.prf, *.prl files
Learn browser decoding from XSS payload
NFT数字藏品系统开发:华为发布首款珍藏版数字藏品
4、数据的完整性
20220725 convolution in automatic control principle
ModuleNotFoundError: No module named ‘pip‘解决办法
To do list application vikunja
Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly
Opencv learning color detection
Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
Yolov5 improvements: add attention mechanism (video tutorial)
NFT数字藏品系统开发:NFT数藏 的最佳数字营销策略有哪些
Qt:列表框、表格、树形控件
Differences in the use of function call pointer parameters *p, * & P
QT: modal, modeless, text box, button, single line input box
Task 1 Titanic top 4% with ensemble modeling
Airiot IOT platform enables the container industry to build a welding station information monitoring system
I don't understand the MySQL 57 version under centos7 when I encounter a problem. I was informed by big Shen who knows it
Drools(2):Drools快速入门