首页 > 解决方案 > Newbie question regarding @app.route("/index")

问题描述

I was messing around with learning python myself, was working on a little HTML website using python. Anyone could please explain the differences between the two applications below?

When it's written like this it doesn't work. (this is an example I got from the top result from google)

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

doesn't works

but when I include the full link .html

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

it works?

标签: pythonroutesapp-route

解决方案


好的,假设您有 index.html 和 index.png 您的代码不知道需要什么文件。即使您只有一个文件,阻止您的代码打开其他文件也是一种安全。文件扩展名是文件的一部分。


推荐阅读