开发者

Django redirection

I have a basic splash page, and I am trying to redirect all urls to the splash EXCEPT for the thank you page (which is linked to after the email form is submitted).

How do I make it such that all my urls will redirect to the splash page with the exception of this one page? Currently, ALL of my urls are re开发者_StackOverflow-directing, even the exception. Here is my code:

urlpatterns = patterns('',
    (r'^$', 'index'),
    (r'^thanks/$', 'thanks'),
    (r'^', 'index_redirect'),

Thank you.


In Django 1.3 you can use the redirect_to along with a pattern that matches everything.

from django.views.generic.simple import redirect_to

urlpatterns = patterns('',
    (r'^$', 'index'),
    (r'^thanks/$', 'thanks'),
    (r'^.*$', redirect_to, {'url': '/'}),
)

WARNING: this WILL match your static resources and images etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜