Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
LearnPython/python_flask.py at master · Arekes/LearnPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Arekes
/
LearnPython
Public
forked from
xianhu/LearnPython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
LearnPython
/
python_flask.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
130 lines (121 loc) · 6.64 KB
master
Breadcrumbs
LearnPython
/
python_flask.py
Copy path
Top
File metadata and controls
Code
Blame
130 lines (121 loc) · 6.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# _*_ coding: utf-8 _*_
# Flask中的一些定义
# =============================================================================================================================
# WSGI: Web服务器网关接口,是一种Web服务使用的协议。
# 路由: 处理URL和函数之间关系的程序称为"路由"。
# 视图函数: 类似于index()这样的,被app.route装饰器注册为路由的函数,或者通过app.add_url_rule()添加路由映射关系的函数,被称为视图函数。
# app.route(): 路由装饰器,可以带参数,参数可以指定数据类型:int/float/path。path类似于字符串,但不将反斜线/当做分隔符。
# =============================================================================================================================
# Flask上下文全局变量
# =============================================================================================================================
# current_app: 程序上下文,当前激活程序的程序实例,所有线程公用一个该实例。
# g: 程序上下文,处理请求时用作临时存储的对象,每次请求都会重设这个变量。
# request: 请求上下文,请求对象,封装了客户端发出的 HTTP 请求中的内容,不同线程之间互不干扰。
# session: 请求上下问,用户会话,用于存储请求之间需要“记住”的值的词典。
# =============================================================================================================================
# Flask支持的4种钩子函数
# =============================================================================================================================
# before_first_request: 注册一个函数,在处理第一个请求之前运行。
# before_request: 注册一个函数,在每次请求之前运行。
# after_request: 注册一个函数,如果没有未处理的异常抛出,在每次请求之后运行。
# teardown_request:注册一个函数,即使有未处理的异常抛出,也在每次请求之后运行。
# =============================================================================================================================
# Jinja2模板使用
# =============================================================================================================================
# 渲染模板: render_template("user.html", name=name)
# (1) 变量: {{ name | capitalize }}
# (2) 控制结构:
# {% if user %}
# Hello, {{ user }}!
# {% else %}
# Hello, Stranger!
# {% endif %}
#
# <ul>
# {% for comment in comments %}
# <li>{{ comment }}</li> {% endfor %}
# </ul>
# (3) 宏-类似于函数:
# {% macro render_comment(comment) %}
# <li>{{ comment }}</li>
# {% endmacro %}
#
# <ul>
# {% for comment in comments %}
# {{ render_comment(comment) }}
# {% endfor %}
# </ul>
# =============================================================================================================================
# Jinja2变量过滤器
# =============================================================================================================================
# safe: 渲染值时不转义
# capitalize: 把值的首字母转换成大写,其他字母转换成小写
# lower: 把值转换成小写形式
# upper: 把值转换成大写形式
# title: 把值中每个单词的首字母都转换成大写
# trim: 把值的首尾空格去掉
# striptags: 渲染之前把值中所有的 HTML 标签都删掉
# =============================================================================================================================
# Flask-Bootstrap基模板中定义的块
# =============================================================================================================================
# doc: 整个 HTML 文档
# html_attribs: <html> 标签的属性
# html: <html> 标签中的内容
# head: <head> 标签中的内容
# title: <title> 标签中的内容
# metas: 一组 <meta> 标签
# styles: 层叠样式表定义
# body_attribs: <body> 标签的属性
# body: <body> 标签中的内容
# navbar: 用户定义的导航条
# content: 用户定义的页面内容
# scripts: 文档底部的 JavaScript 声明
# =============================================================================================================================
# WTForms支持的HTML标准字段,注意添加app.config['SECRET_KEY'] = 'hard to guess string'
# =============================================================================================================================
# StringField 文本字段
# TextAreaField 多行文本字段
# PasswordField 密码文本字段
# HiddenField 隐藏文本字段
# DateField 值为datatime.data格式的文本字段
# DateTimeField 值为datatime.datatime格式的文本字段
# DecimalField 值为decimal.Decimal格式的文本字段
# IntegerField 值为整数的文本字段
# FloatField 值为浮点数的文本字段
# BooleanField 值为True或False的复选框
# RadioField 一组单选框
# SelectField 值唯一的下拉列表
# SelectMultipleField 可选多个值得下拉列表
# FileField 文件上传字段
# SubmitField 表单提交按钮
# FormField 把表单作为字段嵌入另一个表单
# FieldList 一组指定类型的字段
# =============================================================================================================================
# WTForms验证函数
# =============================================================================================================================
# Email 验证电子邮件地址
# EqualTo 比较两个字段的值;常用于要求输入两次密码进行确认的情况
# IPAddress 验证 IPv4 网络地址
# Length 验证输入字符串的长度
# NumberRange 验证输入的值在数字范围内
# Optional 无输入值时跳过其他验证函数
# Required / DataRequired 确保字段中有数据
# Regexp 使用正则表达式验证输入值
# URL 验证 URL
# AnyOf 确保输入值在可选值列表中
# NoneOf 确保输入值不在可选值列表中
# =============================================================================================================================
# uWSGI配置和nginx配置
# =============================================================================================================================
# uwsgi -s /tmp/uwsgi.sock -w MyShow:app --chmod-socket=666
# server {
# listen 80;
# server_name wangluopachong.com;
#
# charset utf-8;
#
# location / {
# include uwsgi_params;
# uwsgi_pass unix:/tmp/uwsgi.sock;
# }
# =============================================================================================================================
You can’t perform that action at this time.