我被指示执行以下操作:修改app.py文件,以便我的网站响应所有可能的URL(也就是不存在的扩展名,如'/ jobs',这意味着如果输入了无效的URL ,它被重定向到家里index.html页面。这里是我的app.py的副本,因为它代表,就如何做到这一点任何想法?烧瓶:重定向不存在的URL
from flask import Flask, render_template #NEW IMPORT!!
app = Flask(__name__) #This is creating a new Flask object
#decorator that links...
@app.route('/') #This is the main URL
def index():
return render_template("index.html", title="Welcome",name="home")
@app.route('/photo')
def photo():
return render_template("photo.html", title="Home", name="photo-home")
@app.route('/about')
def photoAbout():
return render_template("photo/about.html", title="About", name="about")
@app.route('/contact')
def photoContact():
return render_template("photo/contact.html", title="Contact", name="contact")
@app.route('/resume')
def photoResume():
return render_template("photo/resume.html", title="Resume", name="resume")
if __name__ == '__main__':
app.run(debug=True) #debug=True is optional
http://flask.pocoo.org/snippets/57/ – MaxNoe
参见,[如何捕获在路径的任意路径(http://stackoverflow.com/questions/15117416/捕获任意路径在烧瓶路由/),虽然404处理程序在这种情况下更有意义。 – davidism