易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

flash 插入html页面

flash
插入html页面<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="667" height="116">
<param name="movie" value=&quo ......

HTML中的格式标签的简单讲解

格式标签是嵌套在<body></body>之内的。
1.<br>回车 表示强制性的换行,是单独标签。
2.<nobr></nobr>不换行 表示在标记内不换行。用于防止浏览器将标签对中的内容自动换行。
比如:我们所写的代码或其他不能分开的东西。
3.<wbr></wbr>强制换行 其在<nobr></ ......

HTML中元素属性中ID和Name的区别

对于刚刚接触HTML源代码的朋友可能有这样一个疑惑:在一个表单元素中,我如果想用脚本确定某个具体元素,我既可以用他的NAME来索引这个对象,也可以加一个ID来索引它,那这两种方法究竟有什么区别呢?以下我们来具体探讨一下,鉴于本人水平有限,如有描述不当,恳请指教。
我们可以通过一段代码来分析一下其中的微妙差别: ......

jQuery 的 html() 方法的问题。

模板的html 格式如下:
<div id="itemTemplate" style="display:none">
<div class='hotl'>
<div class='l'>
<a href='__ProUrl__'><img src='__ImgUrl__' alt='__ProName__' /></a>
</div>
<ul class='r'>
<li><a href='__ProUrl__' ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号