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() 方法

 
 
 return render(request, "message.html", {"message": u"待办事项添加失败"})
 
 返回到render中指定的message.html页面 并且以字典的方式传值到该模板中比如:{"message": u"待办事项添加失败"}
 
 
redirect
return redirect(resolve_url('index'))可以通过redirect直接进行跳转,不过写的是绝对路径,所以这种相对要好一点

return redirect('/index/')效果同样

HttpRequest

返回参数给前端 {"message": u"待办事项添加失败"}

 

Django之HttpRequest和HttpResponse

 

render

Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
我认为是返回渲染过的html页面和一些变量,还有HttpResponse object
 

render_to_response

Renders a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
返回html页面和HttpResponse object
 
 
  1. response = HttpResponse("Here's the text of the Web page."):
    will create a new HttpResponse 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).

  2. HttpResponseRedirect("http://example.com/"):
    will create a new HttpResponse 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的更多相关文章

  1. 前端面试angular 常问问题总结

    1. angular的数据绑定采用什么机制?详述原理 angularjs的双向数据绑定,采用脏检查(dirty-checking)机制.ng只有在指定事件触发后,才进入 $digest cycle : ...

  2. angular的常见问题

    ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...

  3. Angular面试题四

    二十.angular 的缺点有哪些? 1.强约束 导致学习成本较高,对前端不友好. 但遵守 AngularJS 的约定时,生产力会很高,对 Java 程序员友好. 2.不利于 SEO 因为所有内容都是 ...

  4. AngularJS常见面试题

    本文引自:https://segmentfault.com/a/1190000005836443 问题来源:如何衡量一个人的 AngularJS 水平? ng-if 跟 ng-show/hide 的区 ...

  5. AngularJS 常见面试问题

    ng-if 跟 ng-show/hide 的区别有哪些? 第一点区别是,ng-if 在后面表达式为 true 的时候才创建这个 dom 节点,ng-show 是初始时就创建了,用 display:bl ...

  6. Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect

    在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect   一.HttpRequest捕获 ...

  7. django中HttpRequest请求

    视图的第一个参数必须是HttpRequest对象 在视图函数中,接收的request有如下属性: path:一个字符串,表示请求的页面的完整路径,不包含域名. method:一个字符串,表示请求使用的 ...

  8. $Django 虚拟环境,2.0、1.0路由层区别,Httprequest对象,视图层(fbv,cbv),文件上传

    1 虚拟环境:解决问题同一台机器上可以运行不同版本的django,  1 用pychanrm创建--->files-->newproject--->选择虚拟环境  2 setting ...

  9. day65 request对象,以及方法,response对象,render,redirect

    这里的都是我们会频繁使用到的,用得多了自然就会了,我们写项目都是少不了这些用法的,所以这就把老师的博客粘过来就好了, Request对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...

随机推荐

  1. JavaScript之Date对象

    Javascript中的Date类型是在Java.util.Date基础上创建的. 以1970年01月01日至今的毫秒数来保存时间. 要创建一个Date var now = new Date(); 也 ...

  2. python模块学习之os

    16.1. os-复杂的操作系统接口 Source code: Lib/os.py 该模块提供了使用操作系统相关功能的便携式方法. 如果您只想读或写一个文件,请参阅open(),如果要操作路径,请参阅 ...

  3. unity free asset

    Unity Test Tools https://www.assetstore.unity3d.com/#/content/13802 Sample Assets (beta) https://www ...

  4. NGINX date_udf 定义日志

    Nginx日志自动按日期存储 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,因它的稳定性 ...

  5. mybatis执行多条sql语句

    1,mybatis执行多条sql语句,有以下几种思路, a,存储过程 b,修改jdbc的参数,允许执行多条语句,如下所示: sqlserver可以直接使用begin,end来执行多条语句, mysql ...

  6. Hibernate每个子类一张表(使用XML文件)实例

    在每个子类一张表的情况下,子类映射表与主键和外键关系与父类映射表相关. 类的<joined-subclass>元素用于使用主键和外键关系将子类与父对象进行映射. 在这个例子中,我们将使用h ...

  7. 012android初级篇之Handler机制

    设计Handler类的目的 Handler类被用来注册到一个线程中,这样可以提供一个简单的通信渠道,用来发送数据到这个线程. 可作为UI线程与后台线程交互的几种方法之一. 具体用途 消息的分发和处理, ...

  8. 《转》Ubuntu14.04 openstack juno配置之 ceilometer遥測模块安装配置

    (一)在控制节点上 1.安装的遥測服务 apt-get install -y ceilometer-api ceilometer-collector ceilometer-agent-central ...

  9. json responseJson

    private void doResoponseJson(HttpServletResponse resp,String jsonString){ Trace.logError(Trace.COMPO ...

  10. 加号选择器(ul>li + li)

    <head> <meta charset="UTF-8"> <title>+ selector</title> <style& ...