render httprequest
render
def my_view(request):# View code here...
t = loader.get_template('myapp/index.html')
c = RequestContext(request, {'foo': 'bar'})
return HttpResponse(t.render(c),content_type="application/xhtml+xml")
这就是使用 Django 模板系统的基本规则: 写模板,创建 Template 对象,创建 Context , 调用 render() 方法
redirect
return redirect('/index/')效果同样
HttpRequest
返回参数给前端 {"message": u"待办事项添加失败"}
Django之HttpRequest和HttpResponse

render¶
render_to_response
response = HttpResponse("Here's the text of the Web page.")
:
will create a newHttpResponse
object with HTTP code 200 (OK), and the content passed to the constructor. In general, you should only use this for really small responses (like an AJAX form return value, if its really simple - just a number or so).HttpResponseRedirect("http://example.com/")
:
will create a newHttpResponse
object with HTTP code 302 (Found/Moved temporarily). This should be used only to redirect to another page-
Renders a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
-
通过
httpresponse render_to_response与render返回数据给前端页面,一般返回html(模板)给前端,也可以返回其他数据
render httprequest的更多相关文章
- 前端面试angular 常问问题总结
1. angular的数据绑定采用什么机制?详述原理 angularjs的双向数据绑定,采用脏检查(dirty-checking)机制.ng只有在指定事件触发后,才进入 $digest cycle : ...
- angular的常见问题
ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...
- Angular面试题四
二十.angular 的缺点有哪些? 1.强约束 导致学习成本较高,对前端不友好. 但遵守 AngularJS 的约定时,生产力会很高,对 Java 程序员友好. 2.不利于 SEO 因为所有内容都是 ...
- AngularJS常见面试题
本文引自:https://segmentfault.com/a/1190000005836443 问题来源:如何衡量一个人的 AngularJS 水平? ng-if 跟 ng-show/hide 的区 ...
- AngularJS 常见面试问题
ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...
- Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect
在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect 一.HttpRequest捕获 ...
- django中HttpRequest请求
视图的第一个参数必须是HttpRequest对象 在视图函数中,接收的request有如下属性: path:一个字符串,表示请求的页面的完整路径,不包含域名. method:一个字符串,表示请求使用的 ...
- $Django 虚拟环境,2.0、1.0路由层区别,Httprequest对象,视图层(fbv,cbv),文件上传
1 虚拟环境:解决问题同一台机器上可以运行不同版本的django, 1 用pychanrm创建--->files-->newproject--->选择虚拟环境 2 setting ...
- day65 request对象,以及方法,response对象,render,redirect
这里的都是我们会频繁使用到的,用得多了自然就会了,我们写项目都是少不了这些用法的,所以这就把老师的博客粘过来就好了, Request对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...
随机推荐
- QT错误笔记-Qt Creator needs a compiler set up to build. Configure a compiler in the kit options.
上午在linux环境下,使用QT编译一段C++代码,出现下列错误: 最近在stackoverflow上找到了答案: i was also having the same problem so what ...
- 转-Cannot refer to an instance field arg while explicitly invoking a constructor
编译失败: Cannot refer to an instance field arg while explicitly invoking a constructor 调用方法时不能引用一个实例变量 ...
- hibernate的helloworld实现
首先要新建一个 web project,然后新建一个lib的文件夹并导入相应的jar包 hibernate开发步骤: 1.创建hibernate配置文件 2.创建持久化类 3.创建对象关系映射文件 如 ...
- Java并发编程(六)发布与逸出
"发布(Publish)"一个对象的意思指,使对象能够在作用域之外的代码中使用. 例如: 将一个指向该对象的引用保存到其他代码可以访问的地方 在一个非私有的方法中返回该引用 将引用 ...
- RabbitMQ(一):Windows下RabbitMQ安装
1.Windows下安装RabbitMQ需要以下几个步骤 (1):下载erlang,原因在于RabbitMQ服务端代码是使用并发式语言erlang编写的,下载地址:http://www.erlang. ...
- SSH总结(一)
其实学习struts等框架,不仅要知道怎么用,我们还应该多去看看框架的源码,知道为什么可以这样使用,凡事都知道为什么,以这样的态度学习,我们才能更加深一步的理解原理好实现方式,本类博客主要是个人学习总 ...
- 辛星教你高速掌握PHP的正則表達式
首先说一下,这篇文章也是我在看了数个大牛的博客之后总结出来的,因此首先向这些大牛表示崇高的敬意和感谢,因为人数众多.并且来源也是特别分散,就不一一介绍了,见谅. ************跨语言的主题* ...
- PHP 可以获取客户端哪些访问信息
php是一种弱类型的程序语言,但是最web的 在程序语言中有系统全局函数: $_SERVER <?php echo "".$_SERVER['PHP_SELF'];#当前正在 ...
- ubuntu虚拟化平台libvrit-bin
http://download.cirros-cloud.net/0.3.5/ 下载 cirros-0.3.5-x86_64-disk.img 因为 KVM(准确说是 Libvirt)默认不接受远程管 ...
- [Spring Data MongoDB]学习笔记--_id和类型映射
_id字段的映射: MongoDB要求所有的document都要有一个_id的字段. 如果我们在使用中没有传入_id字段,它会自己创建一个ObjectId. { , "accounts&qu ...