David542
David542

Reputation: 110083

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-directing, even the exception. Here is my code:

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

Thank you.

Upvotes: 1

Views: 583

Answers (1)

Rob Osborne
Rob Osborne

Reputation: 4997

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.

Upvotes: 3

Related Questions