bslima
bslima

Reputation: 1145

Django redirect "/" to index of installed app

I'trying to redirect the / of my domain to point to a index in my "frontend" app. I tried a lot of ways and all of them work. The problem is that my index_view is being called twice for every redirect. Here is my top urls.py

urlpatterns = patterns('',
     url(r'^$', lambda x: HttpResponseRedirect('/frontend/')),
     url(r'^frontend/', include('frontend.urls', namespace="frontend")),
)

And here is my frontend/urls.py

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^alert/create/$', views.create_alert, name="create_alert"),
    url(r'^alert/edit/(\w+)', views.edit_alert, name="edit_alert"),
)

Every time I go to / is calling my views.index twice and I can't see why =/ Am I doing the redirecting wrong ?

Thanks in advance for any help!

Upvotes: 1

Views: 5512

Answers (1)

krak3n
krak3n

Reputation: 966

You can set the root to use your FE url patterns like this:

urlpatterns = patterns('',
    url(r'^', include('frontend.urls', namespace="frontend")),
)

If you wanna forcibly redirect to /frontend/ then you will need a view to handle the redirect.

Maybe look at the Redirect Generic view: https://docs.djangoproject.com/en/1.1/ref/generic-views/#django-views-generic-simple-redirect-to

Upvotes: 3

Related Questions