¡¾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Ò³Ãæ<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 ......
½ñÌ죬×öÏîÄ¿µÄʱºòͻȻ¿´µ½<a target="_blank"></a>Õâ¸ö,¾ÍÍøÉϲéѯÁËÏ ¾ßÌåÈçÏ£¬»¹Ñ§µ½ÆäËû¶îÍâµÄ֪ʶ£¬(*^__^*) ÎûÎû……
targetÊÇ´ò¿ªÁ´½ÓʱÓÃʲôĿ±ê´ò¿ª£¬ÊÇÔÚд°¿ÚÖдò¿ª¾ÍÓÃtarget=_blank£¬ÔÚ¸¸´°¿ÚÖдò¿ª¾ÍÓÃtarget=_parent£¬ÔÚµ±Ç°´°¿ÚÖдò¿ª¾ÍÓÃtarget=_self,
target=_top±íʾÔÚ¶ ......
¶ÔÓÚ¸Õ¸Õ½Ó´¥HTMLÔ´´úÂëµÄÅóÓÑ¿ÉÄÜÓÐÕâÑùÒ»¸öÒÉ»ó£ºÔÚÒ»¸ö±íµ¥ÔªËØÖУ¬ÎÒÈç¹ûÏëÓýű¾È·¶¨Ä³¸ö¾ßÌåÔªËØ£¬ÎҼȿÉÒÔÓÃËûµÄNAMEÀ´Ë÷ÒýÕâ¸ö¶ÔÏó£¬Ò²¿ÉÒÔ¼ÓÒ»¸öIDÀ´Ë÷ÒýËü£¬ÄÇÕâÁ½ÖÖ·½·¨¾¿¾¹ÓÐʲôÇø±ðÄØ£¿ÒÔÏÂÎÒÃÇÀ´¾ßÌå̽ÌÖһϣ¬¼øÓÚ±¾ÈËˮƽÓÐÏÞ£¬ÈçÓÐÃèÊö²»µ±£¬¿ÒÇëÖ¸½Ì¡£
ÎÒÃÇ¿ÉÒÔͨ¹ýÒ»¶Î´úÂëÀ´·ÖÎöÒ»ÏÂÆäÖеÄ΢Ãî²î±ð:
......
»¹ÔÚΪ±ÏÒµÉè¼Æ¶ø·³ÄÕô ¿´¿´ÕâÀï ÎÒ°ïÄã¸ã¶¨¾ÍºÃ
±¾ÈËʵ¼Ê¿ª·¢¾Ñé·á¸» ѧ¹ý¸÷Àà³ÌÐò±àд Ç°ºǫ́¶¼¿ÉÒÔ
ÏÖÔڵŤ×÷²»Ôõô¾°Æøѽ ËùÒÔÕÒµãÍâ¿ìÑø¼Òºý¿Úѽ ºÇºÇ
±¨³êÂï ¹ýµÃÈ¥¾ÍÐÐÁË Ã»Ê²Ã´ÒªÇó ½»¸öÅóÓÑÂï
Èç¹ûÓÐÒâÕß¿ÉÓë±¾ÈËÁªÏµqq604884385 Tel13438309220 ......