¡¾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
Ïà¹ØÎĵµ£º
¸ñʽ±êÇ©ÊÇǶÌ×ÔÚ<body></body>Ö®Äڵġ£
1.<br>»Ø³µ ±íÊ¾Ç¿ÖÆÐԵĻ»ÐУ¬Êǵ¥¶À±êÇ©¡£
2.<nobr></nobr>²»»»ÐÐ ±íʾÔÚ±ê¼ÇÄÚ²»»»ÐС£ÓÃÓÚ·ÀÖ¹ä¯ÀÀÆ÷½«±êÇ©¶ÔÖеÄÄÚÈÝ×Ô¶¯»»ÐС£
±ÈÈ磺ÎÒÃÇËùдµÄ´úÂë»òÆäËû²»ÄÜ·Ö¿ªµÄ¶«Î÷¡£
3.<wbr></wbr>Ç¿ÖÆ»»ÐÐ ÆäÔÚ<nobr></ ......
¿ÉÒÔ˵¼¸ºõÿ¸ö×ö¹ýWeb¿ª·¢µÄÈ˶¼Îʹý£¬µ½µ×ÔªËØµÄIDºÍNameÓÐÊ²Ã´Çø±ð°¢£¿ÎªÊ²Ã´ÓÐÁËID»¹ÒªÓÐNameÄØ?!
¶øÍ¬ÑùÎÒÃÇÒ²¿ÉÒԵõ½×îclassicalµÄ´ð°¸£ºID¾ÍÏñÊÇÒ»¸öÈ˵ÄÉí·ÝÖ¤ºÅÂ룬¶øName¾ÍÏñÊÇËûµÄÃû×Ö£¬IDÏÔÈ»ÊÇΨһµÄ£¬¶øNameÊÇ¿ÉÒÔÖØ¸´µÄ¡£
nameÔÀ´ÊÇΪÁ˱êʶ֮Ó㬵«ÊÇÏÖÔÚ¸ù¾Ý¹æ·¶£¬¶¼½¨ÒéÓÃidÀ´±êÊ¶ÔªËØ¡£
ÒÔÏÂÖ»ÄÜÓ ......
1¡¢Ð½¨ÖÆ×÷chmÎļþµÄ¹¤³Ì
<1> н¨Ò»¸ö´æ´¢CHM¹¤³ÌºÍÖÆ×÷ÆäÔ´ÎļþµÄÎļþ¼Ð¡£ÃüÃûΪchm¡£
<2> ´ò¿ªHTMLHelp Workshop¡£
<3> н¨Ò»¸öproject¡£
<4> ½«project´æ´¢ÔÚÎļþ¼ÐchmÖС£ProjectÃüÃûΪ£ºhelp¡££¨´ËÃû×ÖÊÇ.chmÎļþµÄÃû×Ö£©¡£
<5> Ñ¡Ôñ±àÒëʱҪÉú³ÉµÄÎļþ¡£ ......
¿òÏßÖÆ×÷³£ÓôúÂë
´úÂë
º¬Òå
<table>...</table>
½¨Á¢±í¸ñ£¬ËùÓÐµÄÆäËû±ê¼Ç¶¼ÐèÒªÔڴ˱ê¼ÇÖÐ
<table width=* heigth=*></table>
É趨±í¸ñ¿í¶ÈwidthºÍ¸ß¶Èheight£¬ÊôÐÔÖµ¿ÉÒÔʹÓõãÊý£¬È磺width=50£¬Ò²¿ÉÒÔʹÓðٷֱȣ¬È磺width=50%¡£
<table bgcolor=*></ta ......