我被指示執行以下操作:修改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