易截截图软件、单文件、免安装、纯绿色、仅160KB

【django 学习笔记】12 输出非HTML内容

Django
拥有一些
便利的内建工具帮助你生成常见的非HTML

容:
RSS/Atom
聚合文件
站点地图 (
一个XML
格式文件,
最初由Google
开发,
用于给搜索引擎提示线索)
基础:
视图和MIME
类型
从一个视图返回一个非 HTML

容的关键是在构造一个 HttpResponse

时,
需要指定 mimetype
参数。 通
过改变 MIME
类型,
我们可以通知浏览器将要返回的数据是另一种类
型。
from django.http
import HttpResponse
def my_image(request):

image_data =
open(“/path/to/my/image.png”, “rb”).read()
return
HttpResponse(image_data, mimetype=”image/png”)
生成 CSV
文件
import csv
from django.http
import HttpResponse
# Number of unruly
passengers each year 1995 – 2005. In a real application
# this would likely
come from a database or some other back-end data store.
UNRULY_PASSENGERS =
[146,184,235,200,226,251,299,273,281,304,203]
def
unruly_passengers_csv(request):
# Create the
HttpResponse object with the appropriate CSV header.
response =
HttpResponse(mimetype=’text/csv’)
response['Content-Disposition']
= ‘attachment; filename=unruly.csv’
# Create the CSV
writer using the HttpResponse as the “file.”
writer =
csv.writer(response)
writer.writerow(['Year',
'Unruly Airline Passengers'])
for (year, num) in
zip(range(1995, 2006), UNRULY_PASSENGERS):
writer.writerow([year,
num])
return response
生成 PDF
文件
安装 ReportLab
from reportlab.pdfgen
import canvas
from django.http
import HttpResponse
def
hello_pdf(request):
# Create the
HttpResponse object with the appropriate PDF headers.
response =
HttpResponse(mimetype=’application/pdf’)
response['Content-Disposition']
= ‘attachment; filename=hello.pdf’
# Create the PDF
object, using the response object as its “file.”
p =
canvas.Canvas(response)
# Draw things on the
PDF. Here’s where the PDF generation happens.
# S


相关文档:

html页面表格导出到excel总结


<table id="tableExcel" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="5" align="center">html 表格导出道Excel</td>
</tr>
<tr>
<td>列标题1</td>
<td>列标题2</td>
......

html里title属性换行的方法

众所周知,对于链接和图片,我们可以通过添加title

性以显示一些说明文字,一般情况下,这些文字都是显示成一行,那么有没有办法让它以多行的方式显示呢?解决的方法有两种:
1.将title

性分成几行来写,例如:
<a href=#" title
="说明一
说明二
说明
三">印象派</a> ......

html同一面中的跳转

同一面中的跳转  通过描点 主要用到 window.location.hash 指定描点位置
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Ty ......

主流邮箱能正常显示的HTML邮件的技巧

几乎每个会员制网站都需要通过后台发送邮件来与会员进行沟通,如注册确认、营销推广。这些由站方发给会员的信件,往往纯文本格式已不能满足界面和交互的要求,这时候我们就需要发送HTML页面。由于HTML邮件不是独立的HOST在本站的页面,是寄人篱下的。所以编写HTML邮件与编写HTML页面有很大的不同。因为,各面向网民的主流邮 ......

html 使用JS增加表格行信息

<script language="javascript">
   function addItem()
 {
  var oTable = document.getElementById("whtable");
  var oTbody = oTable.tBodies[0];
   var v = oTbody.rows.length;
   oTbody.insertRow(v); 
   oTbody.rows[v].id="itemtr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号