Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django redirecting blank url to named url

Tags:

python

url

django

I have my url:

url(r'^home/', HomeQuestionView, name='home_question') ,

When I enter localhost:8000/home I get my homepage but what I want is when I just enter I get my homepage. I mean I want to redirect to the above homepage url when user enters only my site likewww.xyz.com not www.xyz.com/home

I dont want to configure in this way

url(r'^', HomeQuestionView, name='home_question') ,

Thanx in advance

like image 766
gamer Avatar asked Dec 15 '22 17:12

gamer


1 Answers

Use generic RedirectView:

from django.views.generic.base import RedirectView

url(r'^$', RedirectView.as_view(url='/home/')),
like image 122
catavaran Avatar answered Jan 02 '23 21:01

catavaran