我对webapp2路由有奇怪的感觉,这就是为什么,在下面的示例中,我的网站上的新闻映射有一个偷窥。
问题是,为什么在某些键中strict_slash=True效果很好并且(生成 301)而在另一个键中根本不起作用(404)?
from webapp2 import WSGIApplication, Route as url
from webapp2_extras.routes import (PathPrefixRoute as patterns,
RedirectRoute as rurl)
from .views import (MainHandler)
from .views_news import (NewsAllHandler, NewsAnnualHandler, NewsMonthlyHandler,
NewsDailyHandler, NewsTagsHandler, NewsTagHandler,
NewsHandler)
app = WSGIApplication([
url('/', MainHandler, 'main'),
patterns('/news', [
rurl('/', NewsAllHandler, 'news_all',
strict_slash=True), # here wont work /news isn't /news/ — get 404
patterns('/tags', [
rurl('/', NewsTagsHandler, 'news_tags',
strict_slash=True), # works well /tags 301 redirects to /tags/
rurl('/<tag:[\w\d-]+>/', NewsTagHandler, 'news_tag',
strict_slash=True),
]),
patterns('/<year:\d{4}>', [
rurl('/', NewsAnnualHandler, 'news_year',
strict_slash=True), # works well /d{4} 301 redirects to /d{4}/
rurl('/<month:\d{2}>/', NewsMonthlyHandler, 'news_month',
strict_slash=True),
rurl('/<month:\d{2}>/<day:\d{2}>/', NewsDailyHandler, 'news_day',
strict_slash=True),
rurl('/<month:\d{2}>/<day:\d{2}>/<slug:[\w\d-]+>/', NewsHandler, 'news',
strict_slash=True),
]),
]),
], debug=True)
我错过了什么吗?请帮帮我,吓死我了!