Skip to content

Commit

Permalink
complete 静态文件和页面路由
Browse files Browse the repository at this point in the history
  • Loading branch information
liukai234 committed May 30, 2020
1 parent f5278fe commit cb7b720
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion python_web/flasky/static.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# 静态文件
# 静态文件
from flask import Flask
from flask import render_template
app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

# 通过路由处理页面间的跳转
@app.route('/r404/')
def r404():
return render_template('404.html')

app.run(host='0.0.0.0', port=19722)
Binary file added python_web/flasky/static/img/main.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion python_web/flasky/templates/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<h1>Hello World!</h1>
<!DOCTYPE html>
<html>

<head>

</head>

<body>
<h1>Hello World!</h1>
<!--标记路由-->
<a href="{{ url_for('r404') }}">404</a>
<!--img css js的静态文件使用的路由-->
<img src="{{ url_for('static', filename='img/main.jpg') }}"
</body>

</html>

0 comments on commit cb7b720

Please sign in to comment.