如何传递来自Django中的HttpResponseRedirect的消息? [英] How to pass a message from HttpResponseRedirect in Django?

查看:385
本文介绍了如何传递来自Django中的HttpResponseRedirect的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,执行一定的任务,并返回到另一个视图,渲染hello.html模板。

I have a view which does the certain task and return to another view which render hello.html template.

def 1stview(request):
   #Do this
   #Do that
   return HttpResponseRedirect('/success/')

def success(request):
    return render_to_response('overview.html', {'overview_files': b, 'total_files':total_files, 'total_size':total_size, 'username': username}, context_instance=RequestContext(request))

成功完成第一个视图后,我想通过 overview.html 。有很多重定向到 success view。我想通过第一个视图传输信息。如何做到这一点?

After successfully completing 1st view I want to pass 'Successful' message in overview.html. There are lots of redirect to success view. I want to transfer message only when going through 1st view. How can I do that?

推荐答案

使用消息框架在页面请求之间发送消息。

Use the messages framework to send messages between page requests.

这篇关于如何传递来自Django中的HttpResponseRedirect的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆