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 newHttpResponseobject 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 newHttpResponseobject 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对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...
随机推荐
- 使用SVN管理unityproject
我们的项目使用SVN管理.这几天遇到了几个问题,攻克了一下.顺便做了一个总结. 1.关于使用SVN管理unity项目的一些设置和说明 首先在unity中进行两部操作:Edit->Proje ...
- CentOS 7 安装以及配置桌面环境
一.安装 GNOME 桌面 1.安装命令: yum groupinstall "GNOME Desktop" "X Window System" " ...
- hdu2588 GCD 给定n,m。求x属于[1,n]。有多少个x满足gcd(x,n)>=m; 容斥或者欧拉函数
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...
- cookie做订单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jsp a href怎么传参数?
jsp中超链接传值使用键值对格式,多个键值对之间用&分隔,即<a href="show.jsp?name=tom&pass=123&score=78,5&quo ...
- Openstack(Kilo)安装系列之环境准备(二)
控制节点.网络节点.计算节点: 一.配置源 1.配置EPEL源 yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-rel ...
- (phpQuery)对网站产品信息采集代码的优化
a.要采集的源链接: http://www.prospecbio.com/Recombinant_Proteins/ b.具体要求:
- 微信 oauth授权2
2.前面请求成功后 会在跳转url后得到 ?code=00b788e3b42043c8459a57a8d8ab5d9f&state=1 3.之后 使用code换取access_token 换取 ...
- Failed to load the JNI shared library jvm.dl
. 原因1:该目录下jvm.dll不存在 2 解决办法:重新安装jdk或者jre并配置好环境变量.copy一个jvm.dll放在该目录下 3 原因2:eclipse的版本与jdk或者jre版本不一致 ...
- 用Python和py2app写独立的Mac OS X 应用
文/lovexiaov(简书作者)原文链接:http://www.jianshu.com/p/afb6b2b97ce9著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 前提 创建一个普通 ...