Django 问题:使用 HttpResponseRedirect 需要帮助

发布于 2024-10-18 23:12:21 字数 915 浏览 1 评论 0原文

我有一个名为 save_service_request 的视图。在代码末尾,它重定向到名为 send_confirmation_email 的视图。

def save_service_request(request):
try:
    # some stuff
except:
        return HttpResponseRedirect(reverse(service_order, args = [contact.client.pk , service_type]))
    return HttpResponseRedirect(reverse(send_confirmation_email, args = [order.pk, service_type]))

现在我想用这个做点什么。如果我在页面上,

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

请使用 HttpResponseRedirect 转到 send_confirmation_email 视图。

但如果之前的url被调用了。

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

将其发送到此

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

这也许可以使用 if 语句。

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:
        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+)/

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+)/

go send it to this

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

This maybe possible using if statements.

, views.service_order),

go to send_confirmation_email view using HttpResponseRedirect.

But if the url before was called.


go send it to this


This maybe possible using if statements.

, views.service_order2),

go send it to this

This maybe possible using if statements.

, views.service_order),

go to send_confirmation_email view using HttpResponseRedirect.

But if the url before was called.

go send it to this

This maybe possible using if statements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-10-25 23:12:21

使用 next 属性:

views.service_order

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

在模板中:

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

在验证表单的视图中:

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

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'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文