python3 flask开发 19 url_for根据参数(传参)动态加载显示文件

templates/index.html(templates文件夹下)




    
    {
    { name }}'s Watchlist
    
    


    

{ { name }}'s Watchlist

{ { movies|length }} Titles

    {% for movie in movies %}
  • { { movie.title }} - { { movie.year }}111
  • {% endfor %}
Walking Totoro
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()


 

 

你可能感兴趣的:(Project,Manager,python,AI,BlockChain)