Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pythonϵÄweb¿ª·¢¿ò¼Ü Django,urlÅäÖÃ

urlÅäÖÃ
ÎÒÃÇÔÚpollsÕâ¸öappÏ´´½¨Ò»¸ö
helloworld.py
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, Django.")
ÐÞ¸Ä urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^newtest/', include('newtest.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^$', 'newtest.helloworld.index'),
# Uncomment the next line to enable the admin:
# (r'^admin/(.*)', admin.site.root),
)
ÆäÖÐ
(r'^$', 'polls.helloworld.index'),
r’^$’ ÊÇΪÁËÆ¥Åä¿Õ´® £¬¾ÍÊÇhttp://localhost:8000/
r’^$’, ‘polls.helloworld.index’),¾ÍÊÇ˵ http://localhost:8000/ Õâ¸öµØÖ·½«»áÖ¸Ïò
polls Õâ¸ö¹¤³ÌÀï helloworld.py ÎļþÀﶨÒåµÄindex·½·¨£¬¿´¿´helloworld.pyÀïÃæÊDz»ÊÇÓиödef index(request):
¾Ù¸öÀý×Ó£¬Èç¹ûÒÔºóÒªÏëÈÃhttp://localhost:8000/ blog Äܱ»·ÃÎÊ£¬Ö»ÐèÒª¼Ó¸ö
r’^blog’ £¬È»ºóÔÚºóÃæдviewsÀ´¿ØÖƽá¹û£¨Õâ¸öÒÔºó»á½²£©£¬¹»·½±ã°É£¡
Èç¹û´Ëʱ web serverÒѾ­Æô¶¯£¬Ö±½ÓË¢ÐÂÒ³Ãæ¾Í¿ÉÒÔ¿´µ½ hello world ÁË
ºÜ·½±ã£¬djangoµÄurlÅäÖÃhelloworld¾ÍÊÇÕâÑù


Ïà¹ØÎĵµ£º

Python Mako Template ѧϰ±Ê¼Ç


MakoÊÇʲô£¿MokoÊÇPythonдµÄÒ»¸öÄ£°å¿â£¬Python¹ÙÍøpython.orgÓõľÍÊÇËüŶ¡£ÆäËû·Ï»°Ò²¾Í²»ÀÛ׸ÁË£¬Ö±½ÓÀ´µã´úÂ룬·½±ãÔĶÁÓëÁ˽â°Ñ¡£
(Mako¹ÙÍøµØÖ·£ºhttp://www.makotemplates.org/ £¬¿ÉÒÔÏÂÔØ°²×°°ü£¬ÍƼöʹÓÃeasy_install°²×°)
from mako.template import Template
mytemplate = Template("hello world!") ......

pythonµÄwebÆôº½

1.»¥ÁªÍø£ºÓÖÒôÒë“ÒòÌØÍø”»òÕß“Ó¢ÌØÍø”£¬ÊÇÖ¸ÔÚARPAÍø»ù´¡ÉÏ·¢Õ¹³öµÄÊÀ½çÉÏ×î´óµÄÈ«ÇòÐÔ»¥ÁªÍøÂç¡£
2.Óйػ¥ÁªÍøµÄЭÒé¿ÉÒÔ·ÖΪ3²ã£º
×îµ×²ãµÄÊÇIPЭÒ飬ÊÇÓÃÓÚ±¨ÎĽ»»»ÍøÂçµÄÒ»ÖÖÃæÏòÊý¾ÝµÄЭÒ飬ÕâһЭÒ鶨ÒåÁËÊý¾Ý°üÔÚÍø¼Ê´«ËÍʱµÄ¸ñʽ¡£
ÉÏÒ»²ãÊÇUDPЭÒéºÍTCPЭÒ飬ËüÃÇÓÃÓÚ¿ØÖÆÊý¾ÝÁ÷µÄ´«Ê ......

PythonÀïÒþ²ØµÄ¡°ìø¡±

ÔÚ pythonµÄlibĿ¼ÀïÓÐÒ»¸ö£ºthis.py£¬ËüÆäʵÊÇÒþ²Ø×ÅÒ»Ê×Ê«£¬Ô´ÂëÈçÏ£º
s =
"""Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......

PythonµÄASCII, GB2312, Unicode , UTF 8

PythonµÄASCII, GB2312, Unicode , UTF-8
ASCII ÊÇÒ»ÖÖ×Ö·û¼¯,°üÀ¨´óСдµÄÓ¢ÎÄ×Öĸ¡¢Êý×Ö¡¢¿ØÖÆ×Ö·ûµÈ£¬ËüÓÃÒ»¸ö×Ö½Ú±íʾ£¬·¶Î§ÊÇ 0-127 Unicode·ÖΪUTF-8ºÍUTF-16¡£
UTF-8±ä³¤¶ÈµÄ£¬×î¶à 6 ¸ö×Ö½Ú£¬Ð¡ÓÚ 127 µÄ×Ö·ûÓÃÒ»¸ö×Ö½Ú±íʾ£¬Óë ASCII ×Ö·û¼¯µÄ½á¹ûÒ»Ñù£¬ASCII ±àÂëϵÄÓ¢ÓïÎı¾²»ÐèÒªÐ޸ľͿÉÒÔµ±×÷ UTF-8 ±àÂë ......

Python²éÕÒÌæ»»

>>> import string
>>> s='adbecf'
>>>
tt=string.maketrans("abc","ABC")
>>> s.translate(tt,"")
'AdBeCf'
>>>
s.translate(tt,"")
ºóÃæµÄÄǸö¿Õ×Ö·û´´¾ÍÊÇÄãҪɾ³ýµÄ×Ö·û£¬±ÈÈçҪɾ³ý»»ÐоÍÊÇs.translate(tt,"\n&q ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ