tags:

views:

22

answers:

2
urlpatterns = patterns('',
    #(r'admin/main/report/', main_page_redirect),
    (r'^admin/', include(admin.site.urls)),
    (r'^', main_page_redirect),
)


def main_page_redirect(request):
    return HttpResponseRedirect('/admin/main/report/?e=+2')

then when i try to go to /localhost then it becomes a infinite loop. does anyone knows how to slove it?

A: 

what is your LOGIN_URL in settings.py set to? The admin site could be trying to redirect you to your login page, which could be the page that is redirecting to the admin site. Just an idea.

Matthew J Morrison
there is LOGIN_URL in settings.py
Grey
there is NO LOGIN_URL in settings
Grey
It was a shot in the dark but worth checking.
Matthew J Morrison
A: 

I was able to recreate this same thing by not having a view mapped to admin/main/report/.

I'm not sure why, but if you create a view and uncomment your urlpattern for admin/main/report/ (and do not use main_page_redirect for that view, you should be good to go.

Here is my example:

def something(request):
    return http.HttpResponseRedirect('/admin/main/report/')

def somethingelse(request):
    return http.HttpResponse("here")

urlpatterns = patterns('',
    url(r'admin/main/report/', somethingelse), #without this i get an infinite loop
    url(r'^admin/', include(admin.site.urls)),
    url(r'', something),
)
Matthew J Morrison
but i need this 2 to redirect to the same page. they both go to '/admin/main/report/?e=+2'
Grey
you can't redirect /admin/main/report/ to /admin/main/report/?anything because you will always redirect to yourself... anything in the querystring (after the ?) is not considered a part of Django's route... what you can do is something like "e = request.GET.get('q', '+2')" in your view to default your ?e=+2
Matthew J Morrison