我正在使用Flask微框架(基于Werkzeug)创建一个新网站来替换当前网站,该框架使用Python(在我的情况下为2.6).
I'm making a new website to replace a current one, using Flask micro-framework (based on Werkzeug) which uses Python (2.6 in my case).
核心功能和许多页面是相同的.但是,使用Flask可以使许多以前的URL与旧的URL不同.
The core functionality and many pages are the same. However by using Flask many of the previous URLs are different to the old ones.
我需要一种以某种方式存储每个旧URL和新URL的方法,这样,如果用户键入一个旧URL,它们将被简单地转发到新URL,并且一切正常.
I need a way to somehow store the each of the old URLs and the new URL, so that if a user types in an old URL they are simply forwarded to the new URL and everything works fine for them.
有人知道在Flask中是否可行?
Does anybody know if this is possible in Flask?
在此先感谢您的帮助:-)
Thank you in advance for your help :-)
推荐答案类似的内容应该可以帮助您入门:
Something like this should get you started:
from flask import Flask, redirect, request app = Flask(__name__) redirect_urls = { 'example/old/': 'example/new/', ... } def redirect_url(): return redirect(redirect_urls[request.url], 301) for url in redirect_urls: app.add_url_rule(url, url, redirect_url)更多推荐
使用Flask微框架将旧网址重定向到新网址
发布评论