views:

593

answers:

2

Hi, I have a form with 2 buttons. depending on the button click user is taken to different url. view function is :

friend_id = request.POST.get('selected_friend_id_list')

history = request.POST.get('statushistory')
if history:
    print "dfgdfgdf"
    return HttpResponseRedirect('../status/')

else:
    return direct_to_template(request, 'friends_list.fbml',
                          extra_context={'fbuser': user,
                                         'user_lastname':user_lastname,
                                         'activemaintab':activemaintab,
                                         'friends':friends,
                                         'friend_list':friend_list})

for template :

<input type="submit"  value="Calendar View" name="calendarview"/>
<input type="submit"  value="Status History" name="statushistory"/>
</form

so my problem is page is not redirecting to the url . If I make HttpResponseRedirect('../') it gives me the correct page but url is not changing.

current page = "friendlist/ status/ so after submitting form my url should be frinedlist/list/ so this should work HttpResponseRedirect('../list/') but url is not getting changed. Any idea? How can I fix this Thanks

A: 

Why do you need to use relative urls? Can you not use absolute urls?

uggedal
FYI http://code.djangoproject.com/ticket/987
alex vasi
+2  A: 

"so my problem is page is not redirecting to the url . If I make HttpResponseRedirect('../') it gives me the correct page but url is not changing."

By "URL" I'm guessing you mean "The URL shown in the browser". It helps if your question is very precise.

First, you must provide an absolute URL. http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect

It's quite clear from the standards (RFC 2616, section 14.30) that an absolute URL is required. Some browsers may tolerate a relative URL. Some don't.

Second, you should never use relative URL's anywhere in your programs.

You should be using reverse.

from django.core.urlresolvers import reverse

def myview(request):
    theURL= reverse('path.to.viewFunction')
    return HttpResponseRedirect(theURL)
S.Lott