概述
index.html(templates文件夹下)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ name }}'s Watchlist</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css">
</head>
<body>
<h2>
{{ name }}'s Watchlist
</h2>
<p>{{ movies|length }} Titles</p>
<ul class="movie-list">
{% for movie in movies %}
<li>{{ movie.title }} - {{ movie.year }}<a href="{{ url_for('static', filename=movie.title) }}">111</a></li>
{% endfor %}
</ul>
<footer>
<small>© 2018 <a href="http://helloflask.com/tutorial">HelloFlask</a></small>
</footer>
<img alt="Walking Totoro" class="totoro" src="{{ url_for('static', filename='images/totoro.gif')}}">
</body>
</html>
from flask import Flask, render_template
import time
import os
app = Flask(__name__)
movies = [
{'title': 'My Neighbor Totoro', 'year': '1988'},
{'title': 'Dead Poets Society', 'year': '1989'},
{'title': 'A Perfect World', 'year': '1993'},
{'title': 'Leon', 'year': '1994'},
{'title': 'Mahjong', 'year': '1996'},
{'title': 'Swallowtail Butterfly', 'year': '1996'},
{'title': 'King of Comedy', 'year': '1999'},
{'title': 'Devils on the Doorstep', 'year': '1999'},
{'title': 'WALL-E', 'year': '2008'},
{'title': 'The Pork of Music', 'year': '2012'},
]
fileDict={'title': 'The Pork of Music', 'year': '2012'}
fileList=[]
fileList.append(fileDict)
print(fileList)
num=0
path = "F:\PythonWebPYCode\mma"
listS = os.listdir(path)
print(listS)
print("*************************")
for i in listS:
#print(i)
os.path.join(path, name)
#i = os.path.join(path, i)
fileDict['title']=i
fileDict['year']=time.ctime(os.path.getatime(i))
print(fileDict)
fileList.append(fileDict.copy())
#fileList[num]=fileList[num]+fileD
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
print(fileList)
@app.route('/')
def index():
return render_template('index.html', name="xxxd", movies=fileList)
if __name__ == '__main__':
app.run()
最后
以上就是自然吐司为你收集整理的python3 flask开发 19 url_for根据参数(传参)动态加载显示文件的全部内容,希望文章能够帮你解决python3 flask开发 19 url_for根据参数(传参)动态加载显示文件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复