Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i redirect from one domain to another in django app?

Normally i would do it with .htaccess but django doesn't have it.

So what is the best way and what is the code for it to redirect from www.olddomain.com to www.newdomain.com?

NOTE: we are not using Apache, but Gunicorn

thanx!

like image 698
mgPePe Avatar asked Feb 07 '13 13:02

mgPePe


2 Answers

The best way to do this is still with your web server rather than Django. This will be much quicker and more efficient than doing it with Django.

Check out this question for more info.

UPDATE

If you really want to do it within django then edit your url conf file (which manages django's url dispatcher) to include the following at the top -

from django.views.generic.simple import redirect_to

urlpatterns = patterns('',   
    (r'^.*$', redirect_to, {'url': 'http://www.newdomain.com'}),
)

For more info check out the documentation.

like image 50
Aidan Ewen Avatar answered Sep 29 '22 18:09

Aidan Ewen


import urlparse
from django.http import HttpResponseRedirect

domain = request.GET['domain'] 
destination = reverse('variable_response',args=['Successful'])
full_address = urlparse.urljoin(domain, destination)
return HttpResponseRedirect(full_address)
like image 26
catherine Avatar answered Sep 29 '22 18:09

catherine