开发者

Django redirection

开发者 https://www.devze.com 2023-03-02 20:21 出处:网络
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).

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

精彩评论

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