【发布时间】:2013-09-27 16:00:27
【问题描述】:
我希望某些东西不是强制性的,所以基本上我希望 www.site.com/endpoint 自动重定向到 www.site.com/something/endpoint。我有办法在一条线上完成吗?
现在我在做:
url(r'^SOMETHING/endpoint$', 'endpoint', name='endpoint'),
url(r'^endpoint$', RedirectView.as_view(url='SOMETHING/endpoint')),
干杯。
【问题讨论】:
-
url(r'^(SOMETHING/)?endpoint$', 'endpoint', name='endpoint')?我没有做过 django,但值得一试。 -
你不能只做
url(r'^[.*]?endpoint$', 'endpoint', name='endpoint')吗? -
这也是我的猜测,但它抱怨视图只需要 1 个参数,但现在给出 2. (SOMETHING/)?似乎成了争论...