Flask Development Micro Movie website (i)

Source: Internet
Author: User
Tags nginx reverse proxy

1. Use of flask knowledge
    • 1. Use shaping, floating-point, Path-type, string-based regular expression routing converter
    • 2. Using GET and POST requests, uploading files, cookie acquisition and response, 404 processing
    • 3. Use template auto-escape, define filter, define global context processor, JINJA2 syntax, include, inherit, define macro
    • 4. Use FLASK-WTF to define the form model, field type, field validation, view processing form, template use form
    • 5. Use Flask-sqlachemy to define the database model, make additions and deletions to the data, data migration
    • 6. Use blueprint to optimize project structure, realize micro movie website foreground and background business logic
    • 7.flask deployment, installation of Nginx, install MySQL service and limit download rate to video streaming via Nginx reverse proxy, limit the number of playback connections a single IP can initiate
2. Video technology used
    • 1.jwplayer Player plug-in
    • 2. Video speed limit limit IP access
    • 3.FLV,MP4 Video Format support
    • 4.Nginx on-demand implementation
3. Description of the environment:
开发系统:Win 7python版本:3.6.3开发工具:pycharm 专业版数据库:MariaDB 5.5.56-Server数据库所在系统:CentOS 7.4
4. Project Model Design
    • Plan your project structure using Flask's blueprint Blueprint
    • Use Flask SQLAlchemy to define the database model associated with the business requirements
    • Generate data tables with MySQL database
4.1 Front-end construction
实现前后台html布局页面搭建实现Jinja2引擎语法引入静态资源文件,404错误页面的处理
4.2 Back-end development
Flask sqlalchemy结合MySQL数据表进行增删改查操作Flask数据分页查询,路由装饰器定义,模板中变量调用,登录会话机制,上传文件Flask wtforms表单验证,Flask自定义应用上下文,自定义权限装饰器对管理系统进行基于角色权限的访问控制Flask的多表关联查询,关键字模糊查询等
4.3 Site Deployment
实现在CentOS服务器上搭建Nginx+MySQL+python环境使用Nginx反向代理多端口多进程部署微电影网站配置Nginx流媒体访问限制参数
5. Front and rear project directory Analysis: 5.1 Reception (Home):
数据模型:models.py表单处理:home/forms.py模版目录:templates/home静态目录:static
5.2 Backstage (Admin):
数据模型:models.py表单处理:admin/forms.py模版目录:templates/admin静态目录:static

The entire project directory looks like this:

6. Building a project directory using Blueprints 6.1 What is a directory
一个应用中或跨应用制作组件和通用的模式,类似于Django中的app
6.2 The role of blueprints
将不同的功能模块化构建大型应用优化项目结构增强可读性,易于维护
6.3 Blueprint Build Project directory 6.3.1 Defining blueprints

In the home directory, under __init__.py文件

from flask import Blueprinthome=Blueprint(‘home‘,__name__)import app.home.views

In the admin directory, under __init__.py文件

from flask import Blueprintadmin=Blueprint(‘admin‘,__name__)import app.admin.views          
6.3.2 Registration Blueprint

Modify the __init__.py file in the app directory

from app.admin import admin as admin_blueprintfrom app.home import home as home_blueprintapp.register_blueprint(home_blueprint)app.register_blueprint(admin_blueprint, url_prefix=‘/admin‘)
6.3.3 Call Blueprint

home目录下的views.py文件

from . import home@home.route("/register/", methods=["GET", "POST"])def register():    pass@home.route("/login/", methods=[‘GET‘, ‘POST‘])def login():    pass

admin目录下的views.py文件

from . import admin@admin.route(‘/‘)def index():    pass@admin.route(‘/login/‘, methods=[‘GET‘, ‘POST‘])def login():    pass

Flask Development Micro Movie website (i)

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.