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 ·ÖÀëÖÐÎÄÓëÓ¢ÎĵĻìºÏ×Ö´®
LiYanrui
posted @ ´óÔ¼ 1 Äêǰ
in ³ÌÐòÉè¼Æ
with tags
python
, 614 ÔĶÁ
Õâ¸öÎÊÌâÊÇ×ö MkIV Ô¤´¦Àí³ÌÐò
ʱ¸ã¶¨µÄ£¬¾ÍÊǰÑÒ»¸ö»ìºÏÁËÖÐÓ¢ÎÄ»ìºÏ×Ö´®·ÖÀëΪӢÎÄÓëÖÐÎĵÄ×Ó×Ö´®£¬Æ©È磬½« ”ÎÒµÄ English ѧµÄ²»ºÃ
&ld ......
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 ......
self
ÀàµÄ·½·¨ÓëÆÕͨµÄº¯ÊýÖ»ÓÐÒ»¸öÌØ±ðµÄÇø±ð——ËüÃDZØÐëÓÐÒ»¸ö¶îÍâµÄµÚÒ»¸ö²ÎÊýÃû³Æ£¬µ«ÊÇ
ÔÚµ÷ÓÃÕâ¸ö·½·¨µÄʱºòÄ㲻ΪÕâ¸ö²ÎÊý¸³Öµ£¬Python»áÌṩÕâ¸öÖµ¡£Õâ¸öÌØ±ðµÄ±äÁ¿Ö¸¶ÔÏó±¾
Éí£¬°´ÕÕ¹ßÀýËüµÄÃû³ÆÊÇself¡£
ÕâÒ²Òâζ×ÅÈç¹ûÄãÓÐÒ»¸ö²»ÐèÒª²ÎÊýµÄ·½·¨£¬Ä㻹ÊǵøøÕâ¸ö·½·¨¶¨ÒåÒ»¸öself²ÎÊý¡£
__init_ ......
python 2.4ÖÐdatetimeÓÐstrftime·½·¨¶øÎÞstrptime·½·¨
¶øpython2.5ÖÐÕâÁ½¸ö·½·¨¾ùÓУ¬¶øÎҵĿª·¢»·¾³ÕýºÃÊÇpython 2.5£¬¶øÔËÐл·¾³ÔòÊÇpython 2.4
¿ª·¢»·¾³Ïµ÷ÊԺõijÌÐò£¬ÔÚ·þÎñÆ÷ÉϾͲ»run¡£²éÁËÒ»ÏÂpythonµÄ¹Ù·½Îĵµ
£¬Ð±Ìåд×Å£ºNew
in version 2.5.
²»¼æÈݵĴúÂëÈçÏ£º
PythonÓïÑÔ
:
test_strptime.py
res ......
ãÂã¶®¶®µÄ°²×°ÁËPython£¬²»Îª±ðµÄ£¬Ö»Îª¸Ïµãʱ÷Ö£¬ÒòΪ¿´¼ûºÜ¶àÓÎÏ·¹«Ë¾¶¼ÒªÇó»áÒ»µãPython»òÕßLUA£¬Ã»°ì·¨£¬»¹ÊǶàѧһµãºÃ£¬·´ÕýÏÐ×ÅÒ²ÊÇÏÐ×Å¡£×Ô¼ºÄ¿Ç°²»¶®LINUX£¬ËùÒÔÔÝÇÒÓÃÓÃWINDOWSϵİɡ£
ÈëÃÅ»¹ºÃÈëÊÖ£¬²»ÊǾÞÄÑ£¬Ö¸³ö¼¸µãÓÐÒâ˼µÄ£º
ûÓлù±¾ÀàÐÍÁË£¬µ±ÎÒ°²cÓïÑÔÓ﷨дint xÊ ......