Flask是用Python编写的Web开发框架之一。通过烧瓶,环路可以在HTML代码中使用神社模板运行,并且可以使用这个被自动生成HTML代码。
代码将以Flask的格式存储在目录中。所以我们将制作两个目录,
- static - 对于静态文件,如images,css,js
- templates - 适用于Html模板
app.py其中将包含所有的Python文件的文件将被存储在将被存储在模板的主目录index.html文件。
app.py
两个示例的app.py代码相同。我们将首先以列表的格式打印带有一些Pokemons名称的Python列表
,然后是表格
# importing modules
from flask import Flask, render_template
# declaring app name
app = Flask(__name__)
# making list of pokemons
Pokemons =["Pikachu", "Charizard", "Squirtle", "Jigglypuff",
"Bulbasaur", "Gengar", "Charmander", "Mew", "Lugia", "Gyarados"]
# defining home page
@app.route('/')
def homepage():
# returning index.html and list
# and length of list to html page
return render_template("index.html", len = len(Pokemons), Pokemons = Pokemons)
# if __name__ == '__main__':
# running app
app.run(use_reloader = True, debug = True)








暂无数据