开发者

Django question: need help using HttpResponseRedirect

I have a view called save_service_request. At the end of the code it redirects to a view called send_confirmation_email.

def save_service_request(request):
try:
    # some stuff
except:
 开发者_如何学JAVA       return HttpResponseRedirect(reverse(service_order, args = [contact.client.pk , service_type]))
    return HttpResponseRedirect(reverse(send_confirmation_email, args = [order.pk, service_type]))

Now I want do something with this. If I am at the page

(r'^quote/service_order/(?P<client_id>\d+)/(?P<request_type>\d+)/$', views.service_order),

go to send_confirmation_email view using HttpResponseRedirect.

But if the url before was called.

(r'^quote/service_order/edit_items/(?P<client_id>\d+)/(?P<request_type>\d+)/$', views.service_order2),

go send it to this

return HttpResponseRedirect(reverse(delete_confirmation, args = [order.pk, service_type]))

This maybe possible using if statements.


Use next attribute:

In views.service_order

context = {'next': reverse('views.send_confirmation_email')}

In template:

<form action='?next={{ next }}'>

In view which validates form:

if 'next' in request.GET:
    return HttpResponseRedirect(request.GET['next'])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜