views:

482

answers:

2

I've got a django project that contain some apps. The main urls.py includes the urls.py from the apps I've enabled, and all is good.

Now I want to configure the project so that when you go to http://testsite/, you'll get the same page that you get when you go to http://testsite/app/.

I can do this by duplicating the corresponding line in the apps urls.py in the projects urls.py, but this feels dirty.

Anyone know a better way?

+5  A: 

Set up a redirect_to from the first url to the second, ie:

from django.conf.urls.defaults import patterns, url, include
from django.views.generic.simple import redirect_to

    urlpatterns = patterns('',
        # Example:
        url(r'^$', redirect_to, {'url':'/app/'}),
        url(r'^app/', include('app.urls')),
        # ...
    )

HTH

bruno desthuilliers
+1  A: 

A redirect is the way to go, because you don't want multiple canonical URLs for the same resource (wastes Google juice). Ideally, you should do the redirect as close to the edge of your stack as possible to conserve server resources. So you can do a Django redirect_to urlconf entry, but you'd be better off with an Apache or nginx or insert-your-webserver-here redirect, so the initial request never has to hit Django at all.

Carl Meyer