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
Ïà¹ØÎĵµ£º
ÕÒÁ˰ëÌìûÕÒ×Å£¬ÖÕÓÚÔÚÓ¢ÎÄÕ¾µãÉÏÕÒµ½£¬»¹ÓиÐлȺÀïµÄʯͷºÍÇòÃÔ
>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0
±ðÍ⸶һ¸öpython¶Ôʱ¼äµÄһЩº¯Êý£¬ºÜºÃÓõÄ
ÎÒÃÇÏȵ¼Èë±ØÐëÓõ½µÄÒ»¸ömodule
>>> import time
ÉèÖÃÒ»¸öʱ¼äµÄ¸ñʽ£¬ÏÂÃæ»áÓõ½
& ......
http://blog.alexa-pro.cn/?p=197
1.´ò¿ªÎļþ´úÂëÈçÏ£º
>>> f = open(”d:test.txt”, “w”)
˵Ã÷£ºµÚÒ»¸ö²ÎÊýÊÇÎļþÃû³Æ£¬°üÀ¨Â·¾¶£»µÚ¶þ¸ö²ÎÊýÊÇ´ò¿ªµÄģʽmode’r'£ºÖ»¶Á£¨È±Ê¡¡£Èç¹ûÎļþ²»´æÔÚ£¬ÔòÅ׳ö´íÎ󣩒w'£ºÖ»Ð´£¨Èç¹ûÎļþ ²»´æÔÚ£¬Ôò×Ô¶¯´´½¨Îļþ£©’a'£º¸½¼ ......
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 ......
°²×°ÎļþÏÂÔØ:
MySQL-python-1.2.2.win32-py2.6.exe
https://docs.google.com/leaf?id=0B-C0ABoe2nuLMDlhZjI5OTQtMWNmYy00ZTNlLWJjNzMtYTc2Y2EzMGFjMzcy&hl=zh_CN
ÐèÒªµÄ¶îÍâdllÎļþÏÂÔØ:
libmmd.dll
https://docs.google.com/leaf?id=0B-C0ABoe2nuLZTk2M2RiZTAtYzY5My00NzNjLTg5ZWEtMzRkZGEyYjUxNThh&hl=zh_C ......