Python Web¿ª·¢ÓëApache2+mod_wsgi²¿Êð
×î½üÔÚ¿´Python Web·½ÃæµÄ¿ª·¢£¬³õ²½½Ó´¥ÁËDjangoºÍweb.py(×¢:ºÍweb2pyÍêÈ«²»Ïà¹Ø)Á½¸ö¿ò¼Ü¡£
Èç¹û½áºÏApache²¿ÊðÐèҪһЩÑо¿£¬¿ÉÄܶÔCGIµÄ²»ÊìϤ°É¡£ËäÈ»mod_pythonÒ²¿ÉÒÔ£¬µ«Ëƺõ¸üÁ÷ÐÐmod_wsgi
,ÎÒÊÇÔÚUbuntu°²×°µÄ,±¾À´ÏëÔ´Âë±àÒëµÄ£¬¿ÉÊÇmakeµÄʱºò×ÜÊDZ¨´í£¬×îºó$sudo apt-get install libapache2-mod-wsgi ,µ¹Ò²¼òµ¥¡£
×¢:Èç¹û²ÉÓñàÒëµÄ·½Ê½£¬ÐèҪԤװapxs2(apxs is the tool for building modules for Apache (apxs2 is for apache2),
$sudo apt-get install apache2-threaded-dev
×°ºÃ¾ÍÊÇÐÞ¸ÄÅäÖÃÎļþÁË,Ö÷ÒªÊÇÐÞ¸Ä/etc/apache2/sites-available/defaultÎļþ:
»ù±¾ÕÕ×ÅÏòµ¼
À´¾Í¿ÉÒÔ£¬ÒòΪÊÇÓ¢Îĵģ¬ÕâÀï¼òÒª½éÉÜÈçÏÂ:
ÔÚVirtualHostÄÚÌí¼Ó
#²ÉÓÃÊØ»¤Ä£Ê½¶ø·ÇÄÚǶģʽ
WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup example.com
££´´½¨python½Å±¾Ö´ÐеıðÃû,ÍƼö³ÌÐò½Å±¾·ÅÔÚ¶ÀÁ¢µÄĿ¼¶ø·ÇDocumentRoot
WSGIScriptAlias /mywebpy /usr/local/mywebpy/index.py
<Directory /usr/local/mywebpy>
Order allow,deny
Allow from all
</Directory>
web.pyʵÀý´úÂëÈçÏÂ:
#!/usr/bin/env python
import web
urls = (
'/(.*)', 'hello'
)
class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)): print'Hello,', name+'!'
application = web.application(urls, globals()).wsgifunc()
µ½ÕâÀï,»¹ÓÐÒ»¸öÎÊÌ⣬ÄǾÍÊÇ´úÂëÖеÄprintÓï¾ä²¢²»±»mod_wsgiÖ§³Ö£¬Äã¿ÉÄܻῴµ½internal errorÖ®ÀàµÄÐÅÏ¢£¬Í¨¹ý/var/log/apache2/error.og¿ÉÒÔ¿´µ½ÏêϸµÄÐÅÏ¢£¬ÄÇÊÇÒòΪ±ê×¼ÊäÈë/Êä³öµÄÓï¾äÔÚWSGIÖÐÊDz»ÔÊÐíµÄ£¬ÔÒòÈçÏ£º
Q: Why do I get the error 'IOError: sys.stdout access restricted by mod_wsgi'?
A: A portable WSGI application or application component should not output anything to standard output. This is because some WSGI hosting mechanisms use standard output to communicate with the web server. If a WSGI application outputs anything to standard outpu
Ïà¹ØÎĵµ£º
×÷ÕߣºÀÏÍõ
PythonËƺõºÜÌÖÑáÐÞÊηû£¬Ã»Óг£¼ûµÄstaticÓï·¨¡£Æ侲̬·½·¨µÄʵÏÖ´óÖÂÓÐÒÔÏÂÁ½ÖÖ·½·¨£º
µÚÒ»ÖÖ·½Ê½£¨staticmethod£©£º
>>> class Foo:
str = "I'm a static method."
def ba ......
from http://blog.alexa-pro.cn/?p=315
´ËÎĵµÊ¹ÓÃƽ̨Ϊ cPAMIE Build 2.0,ºÍ֮ǰµÄ°æ±¾ÓÐÃ÷ÏԵIJî±ð,¾ßÌå¿ÉÖ±½Ó¿´cPAMIE.py Ô´Âë
ÏÂÃæÊÇһЩ³£Óõķ½·¨
ie.navigate('http://blog.alexa.cn') ÓÃÀ´·ÃÎÊÒ»¸öÁ´½Ó¡£
ie.linkClick('linkname') ´ò¿ªÕâ¸öÒ³ÃæÖеÄÒ»¸öÁ¬½Ó ²ÎÊý: name»ò id
ie.textBoxSet('labels','python ......
from http://stackoverflow.com/questions/101268/hidden-features-of-python
http://www.okpython.com/bbs/thread-3434-1-1.html
http://www.okpython.com/bbs/thread-3436-1-2.html
http://www.okpython.com/bbs/thread-3437-1-2.html
http://www.okpython.com/bbs/thread-3438-1-1.html
http://www.okpython.com/bb ......
OS¿âÌṩÁËʹÓø÷ÖÖ²Ù×÷ϵͳ¹¦ÄܵĽӿڡ£
os.name ·µ»Øµ±Ç°²Ù×÷ϵͳÃû£¬¶¨ÒåÁË'posix'£¬'nt'£¬'mac'£¬'os2'£¬'ce'£¬'java'£¨ÎÒʹÓÃwin7/python3.1,Êä³öµÄÊÇnt¡£posix²»ÖªµÀÊÇʲôϵͳ£¬macÓ¦¸ÃÊÇApple»ú°É£¬os2Ò²²»ÖªµÀÊÇʲô¶«¶«£¬ceÓ¦¸ÃÊÇwinCE°É£¬ÕâÑùµÄ»°£¬pythonÓ¦¸ÃÖ§³ÖÏòCEÒÆÖ²°¡£¬Å¼×Ô¼ºÊÔ¹ý£¬Ã»±àÒë³É¹¦£¬java¹À¼ ......