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对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...
随机推荐
- 内核调试神器SystemTap — 探測点与语法(二)
a linux trace/probe tool. 官网:https://sourceware.org/systemtap/ 探測点 SystemTap脚本主要是由探測点和探測点处理函数组成的,来看下 ...
- Backup and Recovery Basics1
一.Backup and Recovery Overview 1.Backup and Recovery Overview 1.1 What is Backup and Recovery? 一般,备份 ...
- Matlab中使用Java api画图图形并保存为jpeg格式
直接上代码: close all; import java.io.*; import java.awt.*; import java.awt.image.BufferedImage; import j ...
- 创建Mat
#include<opencv2/opencv.hpp> #include<iostream> #include<cassert> #include<vect ...
- DataUml Design 教程3-模型与数据库同步
上一节我们已经建立好了数据模型,那么怎么让数据模型和数据库进行同步呢?模型同步到数据库非常简单,只需要模型绑定到数据库即可.DataUml Design目前支持和Oracle与MS Server数据库 ...
- MapReduce源码分析之作业Job状态机解析(一)简介与正常流程浅析
作业Job状态机维护了MapReduce作业的整个生命周期,即从提交到运行结束的整个过程.Job状态机被封装在JobImpl中,其主要包括14种状态和19种导致状态发生的事件. 作业Job的全部状态维 ...
- thinkphp5中的一些关于命名空间的tisp
1.thinkphp5中公共函数文件common中,不需要use,也可以直接使用vendor中的类文件. 2.在类前面的反斜杠作用是,直接使用最外层的命名空间,有时不想use某个X类,却想使用X类时, ...
- 个人博客开发之xadmin与ueditor集成
项目源码下载:http://download.vhosts.cn 1. xadmin 添加ueditor 插件 vim extra_apps\xadmin\plugins\ueditor.py #没有 ...
- xxxxxxclub系统模块分类
不是分析整个程序执行的过程. 分析程序在设计的时候模块怎样分类 针对的是应用程序,name 类的装载:1. Spring配置 基于接口调用hsf 3. 一个页面相应的java类 Spring的xml文 ...
- WPF 属性系统 依赖属性之内存占用分析
关于WPF的属性系统园子内有不少这方面的文章.里面大都提到了WPF依赖属性的在内存方面的优化.但是里面大都一笔带过.那么WPF到底是怎么样节约内存的.我们通过WPF属性和普通的CLR属性对比来看一下W ...