当前位置:网站首页>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
边栏推荐
- Opencv learn read images videos and webcams
- 6. Backup and recovery of MySQL database
- Opencv learning warp Perspective
- Apache dolphin scheduler version 3.0.0-beta-1 was released, and flinksql and Zeppelin task types were added
- Qt:模态非模态、文本框、按钮、单行输入框
- Overview of new features of es11, ES12 and es13
- 6、MySQL数据库的备份与恢复
- Performance test -- lockust performs seckill business scenario test
- Idea -- use @slf4j to print logs
- Now the metauniverse is no longer an existence that is only applied to the social field
猜你喜欢
![Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV](/img/10/40d02da10a6f6779635dc820c074c6.png)
Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV

PG operation and maintenance -- logical backup and physical backup practice

Opencv learn resize and crop

DaemonSet

Check the top 10 best graphics software of the year, meet 99% of your chart needs, and collect it quickly

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

Apache Dolphinscheduler3.0.0-beta-1 版本发布,新增FlinkSQL、Zeppelin任务类型

Image annotation software reference

【C语言】你真的了解printf吗?(printf典型易错,强烈建议收藏)

No .egg-info directory found in xxx\pip-pip-egg-info-mq
随机推荐
Redis migrate tool migration error.
正则表达式规则以及常用的正则表达式
NFT数字藏品开发:数字藏品助力企业发展
Typora免费版下载安装
Task 1 Titanic top 4% with ensemble modeling
This section is intended to supplement
Drools(3):Drools基础语法(1)
Curl post request on the server, using postman tool for parameter conversion
Taishan Office Technology Lecture: page width, height, size and source, and the conversion relationship between inches, centimeters and DPI
Opencv learning drawing shapes and text
Agile and tidy way
Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV
Manifest merger failed with multiple errors, see logs
How to convert multi row data into multi column data in MySQL
Uncover the mystery of cloud native data management: operation level
7月消息,Glassnode数据显示,Deribit上ETH永续期货合约未平仓头寸刚刚达到一个月高点237,959,827美元。
Compose text and icon splicing to realize drawableleft or drawableright
NFT数字藏品开发:数字艺术藏品赋能公益平台
unity3d-对象池的用法
Moonbeam orbiters program: provides a new way for collectors to participate in moonbeam and Moonriver