#coding=utf-8
from flask import Flask,request
app = Flask(__name__)
@app.route('/')
def show():
return "Hello~"
@app.before_first_request
def firstp():
print('第一次请求之前打印这段内容的内容,之后的请求都不会再打印这个内容了')
return 'firstp'
@app.before_request
def everyp():
print('每次请求之前都会打印这段内容')
if __name__ == '__main__':
app.run(debug=True)

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>主页title>
head>
<body>
主页内容
<p>请登录:{{ uname }}p>
body>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>个人中心title>
head>
<body>
个人中心内容
<p>用户名:{{ uname }}p>
body>
html>
#coding=utf-8
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
print('2222222')
return render_template('index.html')
@app.route('/home/')
def home():
print('33333333')
return render_template('home.html')
@app.context_processor
def text():
print('11111111')
return {'uname':'hh'}
if __name__ == '__main__':
app.run(debug=True)
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>500错误页面title>
head>
<body>
<h2>500错误h2>
<p>服务器炸裂了!!!p>
body>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404错误页面title>
head>
<body>
<h2>404错误h2>
<p>您访问的页面被外星人抓走了!!!p>
body>
html>
#coding=utf-8
from flask import Flask,render_template,abort
app = Flask(__name__)
@app.route('/')
def show():
print(uname)
return "Hello~"
@app.errorhandler(500)
def server_handle(error):
return render_template('500.html'),500
@app.errorhandler(404)
def server_handle(error):
return render_template('404.html'),404
if __name__ == "__main__":
# app.run(debug=True)
app.run()

