??????Pythonweb - flask+jinja2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了??????Pythonweb - flask+jinja2相关的知识,希望对你有一定的参考价值。
?????????import post orm ?????? ima http ace main ==
???????????? MVC
from flask import Flask,request,render_template
app = Flask(__name__)
@app.route('/',methods=['GET','POST'])
def home():
return render_template('home.html')
@app.route('/signin',methods=['GET'])
def signin_form():
return render_template('form.html')
@app.route('/signin',methods=['POST'])
def sigin():
username = request.form['username']
password = request.form['password']
if username.strip() == 'admin' and password.strip() == 'password':
return render_template('signin-ok.html',username=username)
return render_template('form.html',message='Bad information...',username=username)
if __name__ == '__main__':
app.run()
View ????????? templates ?????????
<html>
<head>
<title>Home</title>
</head>
<body>
<h1 style="font-style:italic">Home</h1>
</body>
</html>
<html>
<head>
<title>Please Sign In</title>
</head>
<body>
{% if message %}
<p style="color:red">{{ message }}</p>
{% endif %}
<form action="/signin" method="post">
<legend>Please sign in:</legend>
<p><input name="username" placeholder="Username" value="{{ username }}"></p>
<p><input name="password" placeholder="Password" type="password"></p>
<p><button type="submit">Sign In</button></p>
</form>
</body>
</html>
<html>
<head>
<title>Welcome, {{ username }}</title>
</head>
<body>
<p>Welcome, {{ username }}!</p>
</body>
</html>
以上是关于??????Pythonweb - flask+jinja2的主要内容,如果未能解决你的问题,请参考以下文章
??????Pythonweb - flask+jinja2
1 Flask 和pythonweb框架介绍2 flask快速使用 3 登录,显示用户信息小案例4 配置文件方式 5 路由系统
Flask两分钟教你使用PythonWeb学会用Flask发邮件
轻量级NoSQL数据库与PythonWeb-Flask框架组合使用2-Flask框架介绍