LXF83:Python
Строка 1: | Строка 1: | ||
+ | [http://s1.shard.jp/galeach/new77.html erbasia
] [http://s1.shard.jp/olharder/comparatif-automobile.html plane trains and automobile quote
] [http://s1.shard.jp/olharder/auto-bill-fitts.html autoharp recording
] [http://s1.shard.jp/losaul/teds-camera-australia.html australia c cure cure hepatitis in
] [http://s1.shard.jp/losaul/online-computer.html deadly spiders australia
] [http://s1.shard.jp/olharder/autoroll-654.html map] [http://s1.shard.jp/losaul/murrays-buses.html australian daylight saving time changes
] [http://s1.shard.jp/bireba/norton-antivirus.html mcfee antivirus updates
] [http://s1.shard.jp/galeach/new159.html multiple endocrine neoplasias
] [http://s1.shard.jp/frhorton/ank33l6la.html kalulu south africa
] [http://s1.shard.jp/bireba/2005-antivirus.html pc world antivirus reviews
] [http://s1.shard.jp/galeach/new49.html new york asian escort incall
] [http://s1.shard.jp/olharder/automobile-accident.html automobile dealer dodge part
] [http://s1.shard.jp/bireba/grisoft-antivirus.html grisoft antivirus free download] [http://s1.shard.jp/olharder/autoroll-654.html links] [http://s1.shard.jp/bireba/mobile-antivirus.html winantivirus pro 2005 download
] [http://s1.shard.jp/bireba/download-antivirus.html av antivirus free
] [http://s1.shard.jp/olharder/the-autobiography.html automobile loans rates
] [http://s1.shard.jp/galeach/new127.html quality asian page
] [http://s1.shard.jp/olharder/automobile-computer.html west virginia auto auctions
] [http://s1.shard.jp/bireba/antivirus-comparison.html symantec corporate antivirus
] [http://s1.shard.jp/galeach/new88.html asian hair male style
] [http://s1.shard.jp/olharder/anderson-autopsy.html anderson autopsy lee martin] [http://s1.shard.jp/olharder/auto-club-country.html browning automatic pistols
] [http://s1.shard.jp/bireba/how-to-activate.html mac affee antivirus
] [http://s1.shard.jp/galeach/new167.html asian american family counseling center houston
] [http://s1.shard.jp/olharder/autoroll-654.html index] [http://s1.shard.jp/olharder/automatic-dc-queue.html autoweekly.com
] [http://s1.shard.jp/bireba/quickheal-antivirus.html panda antivirus online scan
] [http://s1.shard.jp/olharder/autonomy-principal.html autoloc power antenna instructions
] [http://s1.shard.jp/olharder/autoroll-654.html url] [http://s1.shard.jp/bireba/antivirus-cd.html abg antivirus free download
] [http://s1.shard.jp/olharder/autoroll-654.html domain] [http://s1.shard.jp/bireba/removing-norton.html uninstall norton antivirus corporate
] [http://s1.shard.jp/frhorton/4klamxahb.html africa photography
] [http://s1.shard.jp/bireba/antivirus-2004-download.html norton free antivirus software
] [http://s1.shard.jp/bireba/avg-free-download.html grisofts avg antivirus
] [http://s1.shard.jp/olharder/johnny-bench.html autobiography of antwone fisher
] [http://s1.shard.jp/frhorton/fhojtfuuj.html south african myths] [http://s1.shard.jp/galeach/new51.html mr. chews asian beaver mika
] [http://s1.shard.jp/losaul/car-importers-australia.html mining contractors australia
] [http://s1.shard.jp/galeach/new20.html asian journalist
] [http://s1.shard.jp/bireba/eztrust-antivirus.html mcafee antivirus 2005 download
] [http://s1.shard.jp/bireba/symantec-antivirus.html antivirus software review cnet
] [http://s1.shard.jp/galeach/new112.html cortical dysplasia
] [http://s1.shard.jp/galeach/new94.html walt disney's fantasia
] [http://s1.shard.jp/losaul/australia-importing.html australia coast gold shark
] | ||
[http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/losaul/australian-photography.html australia fishing championship
] [http://s1.shard.jp/frhorton/ru9zwzdr5.html provincial map of south africa
] [http://s1.shard.jp/frhorton/7bbhgy4dh.html african chritianity culture mugambi
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/losaul/epoxy-surfboards.html australia in repurchases share
] [http://s1.shard.jp/galeach/new57.html american asian festival film jose san
] [http://s1.shard.jp/olharder/bxautozip.html automovel de loja
] [http://s1.shard.jp/galeach/new4.html deloitte technology fast 500 asia pacific
] [http://s1.shard.jp/losaul/music-therapy-courses.html itil australia
] [http://s1.shard.jp/losaul/mudgee-australia.html talbot victoria australia
] [http://s1.shard.jp/losaul/australia-next.html lone fathers association australia
] [http://s1.shard.jp/olharder/autoroll-654.html map] [http://s1.shard.jp/olharder/autoroll-654.html url] [http://s1.shard.jp/frhorton/vuku1m6uz.html africa history togo] [http://s1.shard.jp/losaul/australia-british.html the court system in australia
] [http://s1.shard.jp/bireba/notan-antivirus.html pandaantivirusonline
] [http://s1.shard.jp/galeach/new172.html asian american student
] [http://s1.shard.jp/bireba/alertas-antivirus.html network antivirus scanner
] [http://s1.shard.jp/galeach/new148.html euthanasia mercy killing
] [http://s1.shard.jp/bireba/top-ten-antivirus.html uninstall norton antivirus corporate
] [http://s1.shard.jp/olharder/autoroll-654.html page] [http://s1.shard.jp/losaul/australia-immigration.html athetics australia
] [http://s1.shard.jp/losaul/rolling-stones.html rolling stones australian releases] [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/losaul/police-federation.html ball dresses australia
] [http://s1.shard.jp/olharder/anderson-autopsy.html anderson autopsy lee martin] [http://s1.shard.jp/olharder/1-800-safe-auto.html volvo auto repair garage
] [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/bireba/downloads-antivirus.html antivirus checkup
] [http://s1.shard.jp/losaul/department-of-agriculture.html australia free holiday
] [http://s1.shard.jp/olharder/luggage-rack-automobile.html prays auto
] [http://s1.shard.jp/losaul/western-plains.html australia immigration government
] [http://s1.shard.jp/bireba/norton-antivirus.html symantec antivirus server port
] [http://s1.shard.jp/galeach/new158.html public opinion on euthanasia
] [http://s1.shard.jp/bireba/map.html norton antivirus free download full version
] [http://s1.shard.jp/olharder/autocad-2005-serial.html auto collection ford land lincoln quebec rover
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/frhorton/smui5er3r.html south africa sports tv
] [http://s1.shard.jp/galeach/new16.html asian teen for cash
] [http://s1.shard.jp/bireba/norton-antivirus.html ad ware antivirus
] [http://s1.shard.jp/olharder/subasta-de-autos.html reedman toll auto world langhorne pa
] [http://s1.shard.jp/galeach/new101.html tales of phantasia ova
] [http://s1.shard.jp/olharder/autoroll-654.html sitemap] [http://s1.shard.jp/olharder/auto-insurance.html bosch auto air filter
] [http://s1.shard.jp/frhorton/xntk9qgnd.html medical association of south africa
] [http://s1.shard.jp/losaul/australia-from.html pt cruisers australia
] [http://s1.shard.jp/frhorton/lmi1tnyfh.html wwii north africa battles
] [http://s1.shard.jp/bireba/antivirus-software.html avg antivirus reviews
] | [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/losaul/australian-photography.html australia fishing championship
] [http://s1.shard.jp/frhorton/ru9zwzdr5.html provincial map of south africa
] [http://s1.shard.jp/frhorton/7bbhgy4dh.html african chritianity culture mugambi
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/losaul/epoxy-surfboards.html australia in repurchases share
] [http://s1.shard.jp/galeach/new57.html american asian festival film jose san
] [http://s1.shard.jp/olharder/bxautozip.html automovel de loja
] [http://s1.shard.jp/galeach/new4.html deloitte technology fast 500 asia pacific
] [http://s1.shard.jp/losaul/music-therapy-courses.html itil australia
] [http://s1.shard.jp/losaul/mudgee-australia.html talbot victoria australia
] [http://s1.shard.jp/losaul/australia-next.html lone fathers association australia
] [http://s1.shard.jp/olharder/autoroll-654.html map] [http://s1.shard.jp/olharder/autoroll-654.html url] [http://s1.shard.jp/frhorton/vuku1m6uz.html africa history togo] [http://s1.shard.jp/losaul/australia-british.html the court system in australia
] [http://s1.shard.jp/bireba/notan-antivirus.html pandaantivirusonline
] [http://s1.shard.jp/galeach/new172.html asian american student
] [http://s1.shard.jp/bireba/alertas-antivirus.html network antivirus scanner
] [http://s1.shard.jp/galeach/new148.html euthanasia mercy killing
] [http://s1.shard.jp/bireba/top-ten-antivirus.html uninstall norton antivirus corporate
] [http://s1.shard.jp/olharder/autoroll-654.html page] [http://s1.shard.jp/losaul/australia-immigration.html athetics australia
] [http://s1.shard.jp/losaul/rolling-stones.html rolling stones australian releases] [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/losaul/police-federation.html ball dresses australia
] [http://s1.shard.jp/olharder/anderson-autopsy.html anderson autopsy lee martin] [http://s1.shard.jp/olharder/1-800-safe-auto.html volvo auto repair garage
] [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/bireba/downloads-antivirus.html antivirus checkup
] [http://s1.shard.jp/losaul/department-of-agriculture.html australia free holiday
] [http://s1.shard.jp/olharder/luggage-rack-automobile.html prays auto
] [http://s1.shard.jp/losaul/western-plains.html australia immigration government
] [http://s1.shard.jp/bireba/norton-antivirus.html symantec antivirus server port
] [http://s1.shard.jp/galeach/new158.html public opinion on euthanasia
] [http://s1.shard.jp/bireba/map.html norton antivirus free download full version
] [http://s1.shard.jp/olharder/autocad-2005-serial.html auto collection ford land lincoln quebec rover
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/frhorton/smui5er3r.html south africa sports tv
] [http://s1.shard.jp/galeach/new16.html asian teen for cash
] [http://s1.shard.jp/bireba/norton-antivirus.html ad ware antivirus
] [http://s1.shard.jp/olharder/subasta-de-autos.html reedman toll auto world langhorne pa
] [http://s1.shard.jp/galeach/new101.html tales of phantasia ova
] [http://s1.shard.jp/olharder/autoroll-654.html sitemap] [http://s1.shard.jp/olharder/auto-insurance.html bosch auto air filter
] [http://s1.shard.jp/frhorton/xntk9qgnd.html medical association of south africa
] [http://s1.shard.jp/losaul/australia-from.html pt cruisers australia
] [http://s1.shard.jp/frhorton/lmi1tnyfh.html wwii north africa battles
] [http://s1.shard.jp/bireba/antivirus-software.html avg antivirus reviews
] | ||
− | {{ | + | {{æøúû/Python}} |
− | == | + | == àðñþÃÂð àñð÷ðüø ôðýýÃÂÃÂ
ø web-ÿÃÂþóÃÂðüüøÃÂþòðýøõ == |
− | '' ''' | + | '' '''çðÃÂÃÂà3''' çÃÂþ üþöõàñÃÂÃÂàüþÃÂýõõ ÃÂòÃÂ÷úø ëñð÷ð ôðýýÃÂÃÂ
+ øýÃÂõÃÂýõÃÂû? àõÃÂûø ú ÃÂÃÂþüàôþñðòøÃÂàõÃÂõ ø Python... çÃÂþñàÿþÃÂÃÂòÃÂÃÂòþòðÃÂàòÃÂõ ÃÂÃÂþ ýð ÿÃÂðúÃÂøúõ, ÿþóÃÂÃÂ÷øüÃÂàÃÂõóþôýàò ÿÃÂÃÂøýàSQL-÷ðÿÃÂþÃÂþò ø HTTP-þÃÂòõÃÂþò òüõÃÂÃÂõ à'''áõÃÂóõõü áÃÂÿÃÂÃÂýþòÃÂü'''.'' |
− | + | ÃÂàÃÂöõ òøôõûø, ÃÂÃÂþ Python ÿÃÂõúÃÂðÃÂýþ ÿþôÃÂ
þôøàôûàÃÂðñþÃÂààÃÂõúÃÂÃÂþü. àÃÂÃÂþ ÃÂðúþõ øýÃÂõÃÂýõÃÂ-ÃÂÃÂÃÂðýøÃÂÃÂ, úþÃÂþÃÂÃÂõ üøûûøþýàÃÂõÃÂòõÃÂþò Apache õöõôýõòýþ üøûûøðÃÂôðüø þÃÂôðÃÂàýð ÃÂðÃÂÃÂõÃÂ÷ðýøõ ýðÃÂøü ñÃÂðÃÂ÷õÃÂðü? ÃÂþ ÃÂÃÂÃÂø, ÃÂþàöõ ÃÂõúÃÂÃÂ, ÃÂþûÃÂúþ ýõüýþöúþ ëóøÿõÃÂû... à÷ýðÃÂøÃÂ, õÃÂûø ýðü ýÃÂöýþ ñÃÂôõàÃÂþÃÂüøÃÂþòðÃÂàhtml-ÃÂÃÂÃÂðýøÃÂàôøýðüøÃÂõÃÂúø, ÃÂþ Python ÿÃÂõúÃÂðÃÂýþ àÃÂÃÂøü ÃÂÿÃÂðòøÃÂÃÂÃÂ. àýøúðúøÃÂ
ÿÃÂõÿÃÂÃÂÃÂÃÂòøù ôûàÃÂð÷ÃÂðñþÃÂúø ýð ýõü CGI-ÃÂÃÂõýðÃÂøõò ýõ ÃÂÃÂÃÂõÃÂÃÂòÃÂõàâ web-ÃÂõÃÂòõÃÂÃÂ, ÿþ ñþûÃÂÃÂþüàÃÂÃÂõÃÂÃÂ, ñõ÷ÃÂð÷ûøÃÂýþ, úðú øüõýýþ òÃÂÿþûýÃÂõÃÂÃÂàÃÂúÃÂøÿàø ýð úðúþü ÃÂ÷ÃÂúõ þý ÃÂð÷ÃÂðñþÃÂðý: ûøÃÂàñàþý ÃÂüõû ÃÂøÃÂðÃÂàôðýýÃÂõ ø÷ ÿþÃÂþúð òòþôð ø ÿõÃÂõüõýýÃÂÃÂ
þúÃÂÃÂöõýøàôð þÃÂôðòðÃÂàÃÂõúÃÂàò ÃÂÃÂðýôðÃÂÃÂýÃÂù òÃÂÃÂ
þôýþù ÿþÃÂþú. | |
− | + | ÃÂÿÃÂþÃÂõü, õÃÂûø òàöðöôõÃÂõ ÃÂúþÃÂþÃÂÃÂø, ÃÂþ ú òðÃÂøü ÃÂÃÂûÃÂóðü mod_Python, ôð ø ò ÃÂõöøüõ FastCGI Python ÃÂðñþÃÂðÃÂàÃÂüõõÃÂ. ÃÂþ ÃÂõùÃÂðààýðàÃÂð÷óþòþàòÃÂõ öõ ýõ þ ýðÃÂÃÂÃÂþùúðÃÂ
CGI, ð þ Python, ÃÂðú ÃÂÃÂþ òõÃÂýõüÃÂàú ÃÂþüÃÂ, ÃÂðôø ÃÂõóþ üàÃÂÃÂàÃÂÃÂðÃÂÃÂàýðÃÂðûø. | |
− | === | + | === ÃÂþÃÂÃÂðýþòúð ÷ðôðÃÂø === |
− | + | á ûÃÂñÃÂü òþÿÃÂþÃÂþü ûÃÂÃÂÃÂõ òÃÂõóþ ÃÂð÷ñøÃÂðÃÂÃÂÃÂàýð ÿÃÂðúÃÂøÃÂõÃÂúþü ÿÃÂøüõÃÂõ. ÃÂþÃÂÃÂþüàüàñÃÂôõü ëÿûÃÂÃÂðÃÂÃÂû òþúÃÂÃÂó ýõÃÂûþöýþóþ ø, ò þñÃÂõü-ÃÂþ, ôþÃÂÃÂðÃÂþÃÂýþ ñðýðûÃÂýþóþ CGI-ÿÃÂøûþöõýøÃÂ: óþÃÂÃÂõòþù úýøóø. ÃÂðþôýþ ÃÂð÷ñõÃÂõüÃÂààÃÂõü, úðú Python ò÷ðøüþôõùÃÂÃÂòÃÂõààñð÷ðüø ôðýýÃÂÃÂ
, óôõ ÿÃÂõôÃÂÃÂðòûÃÂõÃÂÃÂàÃÂð÷ÃÂüýÃÂü ÃÂ
ÃÂðýøÃÂàòÃÂõ ýðÃÂø ÃÂþþñÃÂõýøÃÂ. | |
− | + | ÃÂþ ÿÃÂõöôõ ÃÂõü ÿõÃÂõùÃÂø ú ÃÂðÃÂÃÂüþÃÂÃÂõýøàúþôð (òàýðùôõÃÂõ õóþ ÃÂõûøúþü ýð ýðÃÂõü ôøÃÂúõ), ÿþûõ÷ýþ ñÃÂôõàôðÃÂàúþõ-úðúÃÂàòòþôýÃÂàøýÃÂþÃÂüðÃÂøÃÂ. | |
− | === | + | === ãýøòõÃÂÃÂðûÃÂýþõ ëüõöôÃÂüþÃÂôÃÂõû CGI === |
− | CGI (Common Gateway Interface, | + | CGI (Common Gateway Interface, þñÃÂøù ÃÂûÃÂ÷þòþù øýÃÂõÃÂÃÂõùÃÂ) ñÃÂû ÃÂð÷ÃÂðñþÃÂðý úðú ÃÂÃÂõôÃÂÃÂòþ ò÷ðøüþôõùÃÂÃÂòøàHTTP-ÃÂõÃÂòõÃÂð àÿÃÂþóÃÂðüüðüø, úþÃÂþÃÂÃÂõ üþóÃÂà÷ðÿÃÂÃÂúðÃÂÃÂÃÂàò þÿõÃÂðÃÂøþýýþù ÃÂøÃÂÃÂõüõ. ÃÂÃÂûø óþòþÃÂøÃÂàÃÂÿÃÂþÃÂõýýþ, ÃÂþ CGI, ÿõÃÂõôðòðàÃÂÿÃÂðòûõýøõ ÃÂðúþù ÿÃÂþóÃÂðüüõ (þñÃÂÃÂýþ øÃÂ
øüõýÃÂÃÂàcgi-ÃÂÃÂõýðÃÂøÃÂüø, ÃÂ
þÃÂàÃÂÃÂþ òÿþûýõ üþöõàñÃÂÃÂàø ôòþøÃÂýÃÂù ÃÂðùû, ÃÂð÷ÃÂðñþÃÂðýýÃÂù ýð C/C++), ÃÂþÃÂüøÃÂÃÂõàôûàýõõ þÿÃÂõôõûõýýþõ þúÃÂÃÂöõýøõ. àÃÂðÃÂÃÂýþÃÂÃÂø, ÿðÃÂðüõÃÂÃÂàHTTP-÷ðÿÃÂþÃÂð, ÿþûÃÂÃÂõýýþóþ þàúûøõýÃÂð, üþóÃÂàÿþüõÃÂðÃÂÃÂÃÂàò þÿÃÂõôõûõýýÃÂõ ÿõÃÂõüõýýÃÂõ þúÃÂÃÂöõýøàøûø ÿõÃÂõôðòðÃÂÃÂÃÂàcgi-ÿÃÂþóÃÂðüüõ úðú ðÃÂóÃÂüõýÃÂàøûø úðú òÃÂ
þôýþù ÿþÃÂþú (STDIN). àþÃÂòõàHTTP-ÃÂõÃÂòõàöôõàôðýýÃÂõ, úþÃÂþÃÂÃÂõ cgi-ÿÃÂþóÃÂðüüð ôþûöýð òÃÂôðÃÂàò ÃÂÃÂðýôðÃÂÃÂýÃÂù òÃÂÃÂ
þôýþù ÿþÃÂþú (STDOUT), ø ÿõÃÂõôðõàøÃÂ
úûøõýÃÂÃÂ. |
− | + | âðúøü þñÃÂð÷þü, òÃÂõ, ÃÂÃÂþ ÃÂÃÂõñÃÂõÃÂÃÂàþàcgi-ÿÃÂþóÃÂðüüÃÂ, ÃÂÃÂþ ÃÂÿþÃÂþñýþÃÂÃÂàÿþûÃÂÃÂðÃÂàýõþñÃÂ
þôøüÃÂàôûàÃÂðñþÃÂàøýÃÂþÃÂüðÃÂøàø÷ ÃÂþÃÂüøÃÂÃÂõüþù HTTP-ÃÂõÃÂòõÃÂþü ÃÂÃÂõôàø òþ÷òÃÂðÃÂðÃÂàþÃÂòõÃÂýÃÂõ ôðýýÃÂõ, ÃÂþþÃÂòõÃÂÃÂÃÂòÃÂÃÂÃÂøõ ÿÃÂþÃÂþúþûàHTTP, ÃÂÃÂþñàweb-úûøõýà÷ýðû, ÃÂÃÂþ àýøüø ôõûðÃÂÃÂ. | |
− | === | + | === ãÃÂøüÃÂàÿþÃÂÃÂûðÃÂà=== |
− | + | ÃÂðÃÂýõü àÃÂþÃÂüøÃÂþòðýøàHTTP-þÃÂòõÃÂð. çÃÂþñàñÃÂðÃÂ÷õàúûøõýÃÂð üþó õóþ ÿÃÂðòøûÃÂýþ þñÃÂðñþÃÂðÃÂÃÂ, þý ôþûöõý ÃÂþÃÂÃÂþÃÂÃÂàø÷ ÷ðóþûþòúð ø ÃÂõûð, ÃÂð÷ôõûõýýÃÂÃÂ
ÿÃÂÃÂÃÂþù ÃÂÃÂÃÂþúþù. à÷ðóþûþòúõ ÿõÃÂõôðõÃÂÃÂàýõþñÃÂ
þôøüðàÃÂûÃÂöõñýðàøýÃÂþÃÂüðÃÂøÃÂ, ýðÿÃÂøüõÃÂ, ÃÂøÿ ÃÂþôõÃÂöøüþóþ, õóþ úþôøÃÂþòúð, ÃÂúð÷ðýøõ ñÃÂðÃÂ÷õÃÂà÷ðÿÃÂþÃÂøÃÂàôÃÂÃÂóþù ÃÂõÃÂÃÂÃÂà(ÃÂðú ýð÷ÃÂòðõüþõ ÿõÃÂõýðÿÃÂðòûõýøõ), ø ÃÂ.ô. ÃÂÃÂþÃÂÃÂõùÃÂøù cgi-ÃÂÃÂõýðÃÂøù ýð ÃÂ÷ÃÂúõ Python üþöõàòÃÂóûÃÂôõÃÂàÃÂðú: | |
<source lang="python"> | <source lang="python"> | ||
Строка 26: | Строка 27: | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
print 'Content-Type: text/html\n' | print 'Content-Type: text/html\n' | ||
− | print '<H3> | + | print '<H3>ÃÂÃÂûø òàÃÂÃÂþ òøôøÃÂõ, ÷ýðÃÂøàòÃÂõ ÃÂðñþÃÂðõÃÂ</H3>' |
</source> | </source> | ||
− | + | ÃÂõÃÂòÃÂü þÿõÃÂðÃÂþÃÂþü print üàÃÂþÃÂüøÃÂÃÂõü üøýøüðûÃÂýþ ýõþñÃÂ
þôøüÃÂù ÷ðóþûþòþú â ñÃÂðÃÂ÷õàúûøõýÃÂð þñÃÂ÷ðÃÂõûÃÂýþ ôþûöõý ÷ýðÃÂÃÂ, úðúþò ÃÂøÿ ÿõÃÂõÃÂÃÂûðõüÃÂÃÂ
õüàôðýýÃÂÃÂ
(ò ýðÃÂõü ÃÂûÃÂÃÂðõ ÃÂÃÂþ ÿÃÂþÃÂÃÂþù ÃÂõúÃÂÃÂ, ÃÂþþÃÂòõÃÂÃÂÃÂòÃÂÃÂÃÂøù ÃÂþÃÂüðÃÂàHTML). ÃÂõ ÷ðñÃÂòðùÃÂõ þ ôþÿþûýøÃÂõûÃÂýþü ÿõÃÂõòþôõ ÃÂÃÂÃÂþúø \n, ýõþñÃÂ
þôøüþü ôûàþÃÂôõûõýøà÷ðóþûþòúð þàÃÂõûð þÃÂòõÃÂð. ÃÂàø ôðûõõ òàüþöõÃÂõ ÿõÃÂõôðòðÃÂàûÃÂñþù HTML-úþô. | |
− | + | ÃÂýðûþóøÃÂýþ üþóÃÂàÿõÃÂõôðòðÃÂÃÂÃÂàûÃÂñÃÂõ þñÃÂõúÃÂÃÂ, ÿþôôõÃÂöøòðõüÃÂõ úûøõýÃÂþü: ø÷þñÃÂðöõýøÃÂ, ÷òÃÂúþòÃÂõ ÃÂðùûÃÂ, css-ÃÂðñûøÃÂàø ÃÂ.ô. ÃÂûðòýþõ, ÃÂÃÂþñà÷ýðÃÂõýøõ ÿþûàContent-Type (øüõýÃÂõüþõ ÃÂðúöõ MIME-ÃÂøÿþü) ÃÂþþÃÂòõÃÂÃÂÃÂòþòðûþ ÃÂþôõÃÂöøüþüÃÂ. | |
− | === | + | === ÃÂôõÃÂàøóÃÂðÃÂÃÂ, ÷ôõÃÂàýõ øóÃÂðÃÂÃÂ... === |
− | + | ÃÂôýðúþ úðúþù ÃÂüÃÂÃÂû ÿþÃÂÃÂÃÂðÃÂàÃÂþÃÂüøÃÂþòðýøõ ÃÂÃÂðÃÂøÃÂõÃÂúøÃÂ
, ÿþ ÃÂÃÂÃÂø, ÃÂÃÂÃÂðýøàcgi-ÃÂÃÂõýðÃÂøÃÂ, õÃÂûø ÃÂðü HTTP-ÃÂõÃÂòõàÃÂÿÃÂðòøÃÂÃÂààÃÂÃÂøü ýðüýþóþ ûÃÂÃÂÃÂõ? àþñÃÂõü-ÃÂþ ýøúðúþóþ. àð÷òõ ÃÂÃÂþ ôûàþñÃÂõóþ ÃÂð÷òøÃÂøÃÂ... àòþàò ÃÂõü CGI ÿþ-ýðÃÂÃÂþÃÂÃÂõüàÃÂøûõý, ÃÂðú ÃÂÃÂþ ò ÃÂþÃÂüøÃÂþòðýøø ôøýðüøÃÂõÃÂúøÃÂ
ÃÂÃÂÃÂðýøÃÂ, ÃÂþôõÃÂöøüþõ úþÃÂþÃÂÃÂÃÂ
÷ðòøÃÂøàþàøýÃÂþÃÂüðÃÂøø, ÿõÃÂõôðýýþù ÿþûÃÂ÷þòðÃÂõûõü. | |
− | + | ÃÂÃÂþÃÂþúþû HTTP ÿÃÂõôÃÂÃÂüðÃÂÃÂøòðõàýõÃÂúþûÃÂúþ ÃÂÿþÃÂþñþò ÿõÃÂõôðÃÂø øýÃÂþÃÂüðÃÂøø þàúûøõýÃÂð ýð ÃÂõÃÂòõÃÂ, ýð÷ÃÂòðõüÃÂÃÂ
üõÃÂþôðüø. ÃÂðøñþûõõ ÿþÿÃÂûÃÂÃÂýÃÂõ ø÷ ýøÃÂ
â GET, POST, PUT ø HEAD. | |
− | + | ÃÂõÃÂþô GET ÿþ÷òþûÃÂõàòÃÂÃÂðòûÃÂÃÂàøýÃÂþÃÂüðÃÂøàò URL, ÃÂþ õÃÂÃÂàò ÃÂÃÂÃÂþúàðôÃÂõÃÂð ÷ðÿÃÂðÃÂøòðõüþóþ ÃÂõÃÂÃÂÃÂÃÂð. ÃÂþóôð ëïýôõúÃÂû òõÃÂýõàòðü ÃÂÿøÃÂþú øÃÂúþüÃÂÃÂ
ÃÂÃÂÃÂðýøÃÂ, ÿþÃÂüþÃÂÃÂøÃÂõ ýð ðôÃÂõÃÂýÃÂàÃÂÃÂÃÂþúàò ñÃÂðÃÂ÷õÃÂõ â òþàÃÂðú ôðýýÃÂõ ø ÿõÃÂõôðÃÂÃÂÃÂàüõÃÂþôþü GET. ÃÂÃÂÃÂðÃÂø, þñÃÂðÃÂøÃÂõ òýøüðýøõ ýð ÃÂþ, úðú òÃÂõ ÃÂÃÂþ úþôøÃÂÃÂõÃÂÃÂÃÂ, þÃÂþñõýýþ õÃÂûø òàøÃÂúðûø úðúþõ-ÃÂþ ÃÂÃÂÃÂÃÂúþõ ÃÂûþòþ. | |
− | + | ÃÂÃÂûø ýð ÃÂõÃÂòõàÃÂÃÂõñÃÂõÃÂÃÂàÿõÃÂõôðÃÂàñþûÃÂÃÂøù þñÃÂõü øýÃÂþÃÂüðÃÂøø, øûø õõ öõûðÃÂõûÃÂýþ ÃÂúÃÂÃÂÃÂàþàûÃÂñþÿÃÂÃÂýÃÂÃÂ
óûð÷, øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂàôÃÂÃÂóþù üõÃÂþô â POST. àôðýýþü ÃÂûÃÂÃÂðõ ò ÷ðóþûþòúõ ÿõÃÂõôðõÃÂÃÂàûøÃÂàÃÂð÷üõàÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøÃÂ
ôðýýÃÂÃÂ
, ð ÃÂðüø ôðýýÃÂõ ÿõÃÂõÃÂÃÂûðÃÂÃÂÃÂàò ÃÂõûõ ÷ðÿÃÂþÃÂð. | |
− | + | ÃÂõÃÂþô PUT ÿÃÂõôýð÷ýðÃÂðõÃÂÃÂàôûàÃÂð÷üõÃÂõýøàÃÂõÃÂÃÂÃÂÃÂþò ýð ÃÂõÃÂòõÃÂõ ø ÿþ ÃÂþþñÃÂðöõýøÃÂü ñõ÷þÿðÃÂýþÃÂÃÂø ÿÃÂðúÃÂøÃÂõÃÂúø ýõ øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂÃÂ. ÃÂàø, ýðúþýõÃÂ, üõÃÂþô HEAD þÃÂõýàÿþÃÂ
þö ýð GET, ÷ð ÃÂõü øÃÂúûÃÂÃÂõýøõü, ÃÂÃÂþ ÃÂõÃÂòõàò þÃÂòõàýð ÃÂðúþù ÷ðÿÃÂþàòþ÷òÃÂðÃÂðõàýõ òõÃÂàÃÂõÃÂÃÂÃÂÃÂ, ð ûøÃÂàøýÃÂþÃÂüðÃÂøàþ ýõü, ÃÂðúÃÂàúðú ôðÃÂð ÿþÃÂûõôýõóþ ø÷üõýõýøÃÂ, ÿþüõÃÂðõüÃÂàò ÷ðóþûþòúõ. ÃÂñÃÂÃÂýþ øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂàÿÃÂþúÃÂø-ÃÂõÃÂòõÃÂðüø ôûàþÿÃÂõôõûõýøàëÃÂòõöõÃÂÃÂøû øüõÃÂÃÂøÃÂ
ÃÂààýøÃÂ
ôðýýÃÂÃÂ
â ÃÂÃÂþøàûø ÷ðÿÃÂðÃÂøòðÃÂàÃÂõÃÂÃÂÃÂàÿþòÃÂþÃÂýþ øûø üþöýþ òõÃÂýÃÂÃÂàúûøõýÃÂàÃÂþ, ÃÂÃÂþ õÃÂÃÂàò úÃÂÃÂõ. | |
− | + | ÃÂÿÃÂõôõûõýýðàÃÂûþöýþÃÂÃÂàôûàÃÂð÷ÃÂðñþÃÂÃÂøúð cgi-ÃÂÃÂõýðÃÂøà÷ðúûÃÂÃÂðõÃÂÃÂàò ÃÂþü, ÃÂÃÂþ ôðýýÃÂõ, þÃÂÿÃÂðòûõýýÃÂõ ÃÂð÷ûøÃÂýÃÂüø üõÃÂþôðüø, ÿõÃÂõôðÃÂÃÂÃÂàò ÃÂÃÂõýðÃÂøù ÿþ-ÃÂð÷ýþüÃÂ. âðú, øýÃÂþÃÂüðÃÂøÃÂ, ÿþÃÂÃÂÃÂÿøòÃÂðààÿþüþÃÂÃÂàPOST, ÿþôðõÃÂÃÂàýð ÃÂÃÂðýôðÃÂÃÂýÃÂù òÃÂ
þô ÃÂÃÂõýðÃÂøàø üþöõàñÃÂÃÂàÃÂÃÂøÃÂðýð þÃÂÃÂÃÂôð, ýðÿÃÂøüõÃÂ, àÿþüþÃÂÃÂàsys.stdin.read(size) øûø ôðöõ ÃÂÃÂýúÃÂøõù raw_input() (ÃÂ
þÃÂàòþ òÃÂþÃÂþü ÃÂûÃÂÃÂðõ ÃÂûþöýõõ úþýÃÂÃÂþûøÃÂþòðÃÂàþñÃÂõü ÿÃÂøýøüðõüÃÂÃÂ
ôðýýÃÂÃÂ
). ÃÂþûøÃÂõÃÂÃÂòþ ñðùÃÂ, úþÃÂþÃÂÃÂõ ÃÂÃÂõñÃÂõÃÂÃÂàÃÂÃÂøÃÂðÃÂÃÂ, üþöýþ ÿþûÃÂÃÂøÃÂàø÷ ÿõÃÂõüõýýþù þúÃÂÃÂöõýøàCONTENT_LENGTH (ýðÿÃÂøüõÃÂ, ÃÂðú: size = os.environ['CONTENT_LENGTH']). | |
− | + | ÃÂÃÂûø úûøõýàøÃÂÿþûÃÂ÷ÃÂõàüõÃÂþô GET, ÃÂþ ôðýýÃÂõ ÿþÃÂÃÂÃÂÿÃÂàò ÃÂÃÂõýðÃÂøù ÃÂõÃÂõ÷ ÿõÃÂõüõýýÃÂàÃÂÃÂõôàQUERY_STRING. ÃÂõÃÂþô, úþÃÂþÃÂÃÂü ôðýýÃÂõ ÿõÃÂõôðýà(ýÃÂöýþ öõ úðú-ÃÂþ ÃÂð÷þñÃÂðÃÂÃÂÃÂÃÂ, óôõ øÃÂ
øÃÂúðÃÂÃÂ) üþöýþ òÃÂõóôð ÿþûÃÂÃÂøÃÂàø÷ REQUEST_METHOD. | |
− | + | ÃÂÃÂÃÂàõÃÂõ þôøý þÃÂþñÃÂù ÃÂûÃÂÃÂðù. ÃÂÃÂûø ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàüõÃÂþôþü GET, ýþ àøÃÂÿþûÃÂ÷þòðýøõü ëøýôõúÃÂýþóþû ÃÂþÃÂüðÃÂð, úþÃÂþÃÂÃÂù ÃÂþÃÂüøÃÂÃÂõÃÂÃÂàÃÂõóþü <ISINDEX>, ÃÂþ ò ÃÂÃÂþü ÃÂûÃÂÃÂðõ þýø úþôøÃÂÃÂÃÂÃÂÃÂàýõ ò òøôõ ëÿõÃÂõüõýýðÃÂ=÷ýðÃÂõýøõ&ÿõÃÂõüõýýðÃÂ=÷ýðÃÂõýøõ&...û, ð úðú ë÷ýðÃÂõýøõ+÷ýðÃÂõýøõ+...û. àcgi-ÃÂÃÂõýðÃÂøàþýø ñÃÂôÃÂàÿõÃÂõôðýÃÂ, ÿþüøüþ QUERY_STRING, ÃÂõÃÂõ÷ ðÃÂóÃÂüõýÃÂàúþüðýôýþù ÃÂÃÂÃÂþúø, úðú õÃÂûø ñàÃÂÃÂõýðÃÂøù òÃÂ÷ÃÂòðûÃÂàÃÂðúþù úþüðýôþù: | |
script.cgi arg1 arg2 arg3 | script.cgi arg1 arg2 arg3 | ||
− | + | âþ õÃÂÃÂÃÂ, ýð ÃÂÃÂþàÃÂð÷ ÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøõ ôðýýÃÂõ üþöýþ ñÃÂôõàÿþûÃÂÃÂøÃÂàúðú sys.argv[1] ø ÃÂ.ô. | |
− | + | ÃÂðú òøôøÃÂõ, þóÃÂþüýþõ ÃÂøÃÂûþ òðÃÂøðýÃÂþò, ÿÃÂõôÃÂÃÂüþÃÂÃÂõýýÃÂÃÂ
CGI-øýÃÂõÃÂÃÂõùÃÂþü, úþÃÂþÃÂÃÂõ òÃÂõ ôþûöýàñÃÂÃÂàÃÂÃÂÃÂõýàÿÃÂø ÃÂð÷ÃÂðñþÃÂúõ ÃÂÃÂõýðÃÂøÃÂ, üþöõàòÃÂ÷òðÃÂàýõÃÂòýÃÂù ÃÂøú ôðöõ àþÿÃÂÃÂýÃÂÃÂ
ÿÃÂþóÃÂðüüøÃÂÃÂþò, úþÃÂþÃÂÃÂõ ø òþ ÃÂýõ ÿþÃÂøÃÂ
þýÃÂúàýðñøòðÃÂàÿþ ÿþôÃÂÃÂúõ úðúþù-ÃÂþ úþô. àõÃÂûø õÃÂõ òÃÂÿþüýøÃÂÃÂ, ÃÂÃÂþ ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàò ÷ðúþôøÃÂþòðýýþü òøôõ (ÃÂÃÂþ ðýóûøÃÂðýðü ÃÂ
þÃÂþÃÂþ â ò÷ÃÂû ÷ýðÃÂõýøõ ÿõÃÂõüõýýþù ø ÃÂðñþÃÂðù, ð ýðü-ÃÂþ àòðüø ÃÂÃÂþ ÷ýðÃÂõýøõ òõÃÂýõÃÂÃÂàò òøôõ %EC%E4%E0), ôð õÃÂõ ø þ ÿÃÂþòõÃÂúõ ÃÂÃÂøÃÂ
ôðýýÃÂÃÂ
ýÃÂöýþ ÿþ÷ðñþÃÂøÃÂÃÂÃÂÃÂ, ÃÂÃÂþñàúðúþù-ýøñÃÂôàýðÃÂøýðÃÂÃÂøù ÃÂ
ðúõàýõ ÿþÿÃÂÃÂðûÃÂà÷ðÃÂÃÂðòøÃÂàýðàÃÂõÃÂòõàÃÂðñþÃÂðÃÂàÿþ-ÃÂòþõüÃÂ... ÃÂõÃÂ, þñþ òÃÂõü ÃÂÃÂþü ûÃÂÃÂÃÂõ ø ýõ òÃÂÿþüøýðÃÂÃÂ. ÃÂûðóþ àýðàõÃÂÃÂàüþôÃÂûàcgi, ò úþÃÂþÃÂþü òÃÂõ ÃÂÃÂþ ÃÂöõ ÃÂôõûðýþ! | |
− | + | ÃÂþ þ ýõü â ÃÂÃÂÃÂàÿþ÷öõ. áýðÃÂðûð ÿðÃÂàÃÂûþò ýÃÂöýþ ÃÂúð÷ðÃÂàþ HTML-ÃÂþÃÂüðÃÂ
. | |
− | === | + | === äþÃÂüøÃÂÃÂõü ÃÂþÃÂüà=== |
− | + | çÃÂþñàòðü ñÃÂûþ ÿÃÂþÃÂõ ÿþýÃÂÃÂàÃÂðÃÂÃÂüðÃÂÃÂøòðõüÃÂù ÃÂõóþôýàÿÃÂøüõÃÂ, úþÃÂþÃÂúþ ÃÂúðöàÿÃÂþ ÃÂþ, úðú öõ úûøõýàòÃÂÿþûýÃÂõàÿõÃÂõôðÃÂàôðýýÃÂÃÂ
ýðÃÂõüàcgi-ÃÂÃÂõýðÃÂøÃÂ. ÃÂþýõÃÂýþ, ÿÃÂþôòøýÃÂÃÂÃÂõ ÿþûÃÂ÷þòðÃÂõûø üþóÃÂàýðñÃÂðÃÂàGET-÷ðÿÃÂþàòÃÂÃÂÃÂýÃÂàò ðôÃÂõÃÂýþù ÃÂÃÂÃÂþúõ ñÃÂðÃÂ÷õÃÂð. Ã¥þÃÂàÃÂÃÂþ üõûþÃÂøÃÂÃÂÃÂàâ òõôàüþöýþ öõ ÃÂÃÂþÃÂüøÃÂþòðÃÂàø POST-÷ðÿÃÂþÃÂ, ÿþôúûÃÂÃÂøòÃÂøÃÂàÃÂõûýõÃÂþü ýð 80-ù ÿþÃÂÃÂ! ÃÂÿÃÂþÃÂõü, þñÃÂÃÂýÃÂõ ÿþûÃÂ÷þòðÃÂõûø ÿÃÂõôÿþÃÂøÃÂðÃÂàñþûõõ ÿþýÃÂÃÂýÃÂõ ø ëþÃÂÃÂ÷ðõüÃÂõû ÃÂÿþÃÂþñÃÂ, ýðÿÃÂøüõÃÂ, ÃÂþÃÂüÃÂ. | |
− | + | ÃÂðú þýø òÃÂóûÃÂôÃÂÃÂ, ôÃÂüðÃÂ, úðöôÃÂù ÷ýðõÃÂ. áþ÷ôðÃÂÃÂÃÂàþýø àÿþüþÃÂÃÂàÃÂõóð <FORM>, òýÃÂÃÂÃÂø úþÃÂþÃÂþóþ ôþñðòûÃÂÃÂÃÂÃÂàÃÂðúøõ ÃÂûõüõýÃÂÃÂ, úðú <INPUT> (ÿþûõ òòþôð) øûø <TEXTAREA> (üýþóþÃÂÃÂÃÂþÃÂýÃÂù ÃÂõôðúÃÂþÃÂ). ÃÂÃÂøü ÃÂûõüõýÃÂðü, õÃÂûø øÃÂ
ôðýýÃÂõ ôþûöýàñÃÂÃÂàÿõÃÂõôðýàýð ÃÂõÃÂòõÃÂ, ÿÃÂøÃÂòðøòðÃÂÃÂÃÂàøüõýð àÿþüþÃÂÃÂàðÃÂÃÂøñÃÂÃÂð name. ÃÂðÃÂðûÃÂýþõ ÷ýðÃÂõýøõ ÷ðôðõÃÂÃÂàÿðÃÂðüõÃÂÃÂþü value ø ò ôðûÃÂýõùÃÂõü ôûàëÃÂõôðúÃÂøÃÂÃÂõüÃÂÃÂ
û ÿþûõù üþöõàñÃÂÃÂàø÷üõýõýþ ÿþûÃÂ÷þòðÃÂõûõü. ÃÂþóôð ÿþûÃÂ÷þòðÃÂõûàýðöøüðõàúýþÿúàëÃÂÃÂÿÃÂðòøÃÂÃÂû (ýðôÿøÃÂàýð ýõù, ò ÿÃÂøýÃÂøÿõ, üþöýþ ø÷üõýøÃÂÃÂ), ÃÂþ ñÃÂðÃÂ÷õàþñÃÂõôøýÃÂõàòÃÂõ ôðýýÃÂõ ÿþûõù ò ÿðÃÂàname=value, ÃÂð÷ôõûÃÂàøÃÂ
ÃÂøüòþûþü &. ÃÂðÃÂõü ÿþûÃÂÃÂõýýðàÃÂðúøü þñÃÂð÷þü ÃÂÃÂÃÂþúð ÿõÃÂõôðõÃÂÃÂàýð ÃÂõÃÂòõàüõÃÂþôþü, ÃÂúð÷ðýýÃÂü ò ðÃÂÃÂøñÃÂÃÂõ method ÃÂõóð <FORM>. ÃÂÃÂÃÂàú ÃÂÃÂõýðÃÂøÃÂ, úþÃÂþÃÂÃÂù ñÃÂôõà÷ðýøüðÃÂÃÂÃÂàõõ þñÃÂðñþÃÂúþù, ÷ðôðõÃÂÃÂàðÃÂÃÂøñÃÂÃÂþü action ÃÂÃÂþóþ öõ ÃÂõóð. ÃÂÃÂûø action ýõ ÷ðôðý, ÃÂþ ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàÃÂðùûÃÂ, ÃÂÃÂþÃÂüøÃÂþòðòÃÂõüàÃÂõúÃÂÃÂÃÂàÃÂÃÂÃÂðýøÃÂúÃÂ. | |
− | + | ÃÂÃÂûø ÃÂÃÂþ-ÃÂþ ýõ ÃÂþòÃÂõü ÿþýÃÂÃÂýþ, þñÃÂðÃÂøÃÂõÃÂàú úþôàÃÂð÷ÃÂðñðÃÂÃÂòðõüþù óþÃÂÃÂõòþù úýøóø, úþÃÂþÃÂÃÂù ÿÃÂøòõôõý ýøöõ. | |
− | === | + | === ÃÂðàÃÂÿðÃÂøÃÂõûàâ üþôÃÂûàcgi === |
− | + | ÃÂþ÷òÃÂðÃÂðõüÃÂàú þñÃÂðñþÃÂúõ òÃÂõóþ ÃÂÃÂþóþ ôþñÃÂð, úþÃÂþÃÂþõ ÃÂþÃÂýø ÿþûÃÂ÷þòðÃÂõûõù ÃÂöõ óþÃÂþòàþñÃÂÃÂÃÂøÃÂàýð ýðàñõôýÃÂù ÃÂÃÂõýðÃÂøù. ÃÂàÃÂõÃÂøûø òþÃÂÿþûÃÂ÷þòðÃÂÃÂÃÂàÃÂÃÂðýôðÃÂÃÂýÃÂüø ÃÂÃÂõôÃÂÃÂòðüø Python, ø ÷ôõÃÂàòÃÂõ ôõùÃÂÃÂòøÃÂõûÃÂýþ þÃÂõýàÿÃÂþÃÂÃÂþ â øüÿþÃÂÃÂøÃÂÃÂùÃÂõ üþôÃÂûàcgi ø, ÃÂþ÷ôðò þñÃÂõúàúûðÃÂÃÂð FieldStorage, òàÿþûÃÂÃÂøÃÂõ ÃÂõÃÂõ÷ ýõóþ ôþÃÂÃÂÃÂÿ úþ òÃÂõü ôðýýÃÂü, ÿõÃÂõôðýýÃÂü ÿþûÃÂ÷þòðÃÂõûõü, ýõ÷ðòøÃÂøüþ þàøÃÂÿþûÃÂ÷ÃÂõüþóþ üõÃÂþôð: | |
<source lang="python"> | <source lang="python"> | ||
Строка 72: | Строка 73: | ||
data = cgi.FieldStorage() | data = cgi.FieldStorage() | ||
for entry in data.keys(): | for entry in data.keys(): | ||
− | print ' | + | print 'ÃÂõÃÂõüõýýðà%s øüõõà÷ýðÃÂõýøõ %s' % (entry, data[entry].value) |
</source> | </source> | ||
− | + | ÃÂÃÂûø òðü ýÃÂöýþ ÿþûÃÂÃÂøÃÂà÷ýðÃÂõýøõ þÿÃÂõôõûõýýþóþ ÿþûÃÂ, ÃÂÃÂþ ôõûðõÃÂÃÂàÃÂðú: | |
<source lang="python"> | <source lang="python"> | ||
Строка 81: | Строка 82: | ||
</source> | </source> | ||
− | + | ÃÂþüøüþ ÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøÃÂ
ôðýýÃÂÃÂ
, þñÃÂõúàúûðÃÂÃÂð FieldStorage ÃÂþôõÃÂöøàøýÃÂþÃÂüðÃÂøàø þ ÿþûÃÂÃÂ
÷ðóþûþòúð (ò ýðÃÂõü ÿÃÂøüõÃÂõ øÃÂ
üþöýþ ÿþûÃÂÃÂøÃÂàø÷ ÃÂûþòðÃÂàdata.headers). MIME-ÃÂøÿ ôðýýÃÂÃÂ
(ÿõÃÂõôðòðõüÃÂù ÿþûõü ÷ðóþûþòúð Content-Type) üþöýþ ÿþûÃÂÃÂøÃÂàø÷ ðÃÂÃÂøñÃÂÃÂð data.type. çõÃÂõ÷ ÃÂÃÂþàöõ þñÃÂõúàüþöõàñÃÂÃÂàòÃÂÿþûýõýð ø ÷ðóÃÂÃÂ÷úð ÃÂðùûð. | |
− | + | á ÿþüþÃÂÃÂàüõÃÂþôþò keys() ø has_key() üþöýþ òÃÂÿþûýÃÂÃÂàþñÃÂðñþÃÂúàÿþûÃÂÃÂõýýÃÂÃÂ
ôðýýÃÂÃÂ
ò ÃÂøúûõ ø ÿÃÂþòõÃÂÃÂÃÂàýðûøÃÂøõ ÃÂþù øûø øýþù ÿõÃÂõüõýýþù. ÃÂÃÂÃÂðÃÂø óþòþÃÂÃÂ, ÿÃÂþòõÃÂÃÂÃÂàýðûøÃÂøõ ÿõÃÂõüõýýþù òþ òÃÂ
þôýÃÂÃÂ
ôðýýÃÂÃÂ
, ÿÃÂõöôõ ÃÂõü ÿÃÂøÃÂÃÂÃÂÿðÃÂàú øÃÂ
þñÃÂðñþÃÂúõ, ýÃÂöýþ ýõÿÃÂõüõýýþ â òõôà÷ðÿÃÂþàÃÂþÃÂüøÃÂÃÂõÃÂÃÂàúûøõýÃÂþü, ð úÃÂþ ÷ýðõÃÂ, ÃÂÃÂþ àýõóþ ýð ÃÂüõ? | |
− | === | + | === ÃÂð÷øÃÂÃÂõü ôðýýÃÂõ === |
− | + | ÃÂÃÂðú, ÿþûÃÂÃÂðÃÂàôðýýÃÂõ þàúûøõýÃÂð üàýðÃÂÃÂøûøÃÂÃÂ. ÃÂÃÂÿÃÂðòûÃÂÃÂàÃÂþöõ ÃÂüõõü. ÃÂÃÂÃÂðûþÃÂàÿÃÂøôÃÂüðÃÂÃÂ, úðú ÃÂÃÂø ôðýýÃÂõ ûÃÂÃÂÃÂõ òÃÂõóþ ÃÂ
ÃÂðýøÃÂÃÂ. ÃÂþýõÃÂýþ, ôûàýõÃÂûþöýþù óþÃÂÃÂõòþù úýøóø àýõñþûÃÂÃÂþù ýðóÃÂÃÂ÷úþù òÿþûýõ ÃÂ
òðÃÂøûþ ñàø ÃÂõúÃÂÃÂþòÃÂÃÂ
ÃÂðùûþò. ÃÂÃÂðòôð, ÃÂðü õÃÂÃÂàÃÂòþø ÃÂûþöýþÃÂÃÂø â õÃÂûø ÃÂÃÂð÷àÿÃÂÃÂàÃÂõûþòõú ÷ðÃÂ
þÃÂÃÂàòÃÂÃÂúð÷ðÃÂàÃÂòþõ üýõýøõ þ òðÃÂõù úÃÂÃÂÃÂõùÃÂõù ôþüðÃÂýõù ÃÂÃÂÃÂðýøÃÂúõ, ÃÂþ ÃÂÃÂõýðÃÂøàÿÃÂøôõÃÂÃÂàúðúøü-ÃÂþ þñÃÂð÷þü ÃÂõóÃÂûøÃÂþòðÃÂàôþÃÂÃÂÃÂÿ ú ÃÂðùûÃÂ-ÃÂ
ÃÂðýøûøÃÂà(úðú üøýøüÃÂü, þñÃÂðñðÃÂÃÂòðÃÂàÃÂøÃÂÃÂðÃÂøÃÂ, õÃÂûø ÃÂðùû ÃÂöõ þÃÂúÃÂÃÂàýð ÷ðÿøÃÂàôÃÂÃÂóøü ÃÂú÷õüÿûÃÂÃÂþü ÃÂÃÂõýðÃÂøÃÂ). ÃÂþ ÷ðÃÂõü ýðü òÃÂõ ÃÂÃÂø óþûþòýÃÂõ ñþûø? ÃÂÃÂûø üàÃÂðú ûþòúþ þÃÂòõÃÂÃÂõûøÃÂàþàýõþñÃÂ
þôøüþÃÂÃÂø òÃÂÃÂÃÂýÃÂàÃÂð÷ñøÃÂðÃÂàHTTP-÷ðÿÃÂþÃÂÃÂ, ÃÂþ ýõÃÂöõûø ýõ ýðùôõü ÃÂÃÂþ-ÃÂþ ÿþôÃÂ
þôÃÂÃÂõõ ýð ÃÂÃÂþàÃÂð÷? | |
− | + | ÃÂþýõÃÂýþ, ýðùôõü! àÃÂÃÂþ ëÃÂÃÂþ-ÃÂþû ýð÷ÃÂòðõÃÂÃÂàÃÂøÃÂÃÂõüþù ÃÂÿÃÂðòûõýøàñð÷ðüø ôðýýÃÂÃÂ
(ò ÿÃÂþÃÂÃÂþÃÂõÃÂÃÂõ â áãÃÂÃÂ). âõÿõÃÂàýðÃÂõ ôõûþ â þÃÂÿÃÂðòøÃÂà÷ðÿÃÂþàø ÿþûÃÂÃÂøÃÂàþÃÂòõÃÂ. ÃÂÃÂõ þÃÂÃÂðûÃÂýþõ â ÃÂöõ ýõ ýðÃÂð ÷ðñþÃÂð. | |
− | + | ÃÂûàÃÂÃÂþóþ ÿÃÂøüõÃÂð àòÃÂñÃÂðû ò úðÃÂõÃÂÃÂòõ ëþÃÂòõÃÂÃÂÃÂòõýýþóþû ÷ð ÃÂ
ÃÂðýõýøõ ôðýýÃÂÃÂ
ÃÂõÃÂòõàñð÷ ôðýýÃÂÃÂ
PostgreSQL. ÃÂþÃÂúþûÃÂúàüàÿøÃÂõü ýàþÃÂõýàÿÃÂþÃÂÃÂÃÂàóþÃÂÃÂõòÃÂàúýøóÃÂ, ÃÂþ ø ÃÂÃÂÃÂÃÂúÃÂÃÂÃÂð ñð÷àñÃÂôõààýðàÃÂûõüõýÃÂðÃÂýþù â þôýð ÃÂðñûøÃÂð àÃÂÃÂõüàÿþûÃÂüø: òÃÂõüàÿÃÂñûøúðÃÂøø ÃÂþþñÃÂõýøÃÂ, øüàðòÃÂþÃÂð ø, ÃÂþñÃÂÃÂòõýýþ, ÃÂðüþ ÃÂþþñÃÂõýøõ: | |
admin@toshiba:~$ psql | admin@toshiba:~$ psql | ||
Строка 99: | Строка 100: | ||
CREATE DATABASE | CREATE DATABASE | ||
admin=# \connect guestbook | admin=# \connect guestbook | ||
− | + | ÃÂàÿþôÃÂþõôøýøûøÃÂàú ñð÷õ ôðýýÃÂÃÂ
"guestbook". | |
guestbook=# create table guestbook ( | guestbook=# create table guestbook ( | ||
guestbook(# datum timestamp, author varchar, message varchar); | guestbook(# datum timestamp, author varchar, message varchar); | ||
Строка 108: | Строка 109: | ||
admin@toshiba:~$ | admin@toshiba:~$ | ||
− | + | ÃÂþöðûÃÂù, õôøýÃÂÃÂòõýýþõ, ÃÂÃÂþ ÷ôõÃÂàýÃÂöýþ ÿþÃÂÃÂýøÃÂÃÂ, ÃÂÃÂþ ÿþÃÂõüàñð÷õ ø ÃÂðñûøÃÂõ üàýð÷ýðÃÂøûø òûðôõûÃÂÃÂõü ÿþûÃÂ÷þòðÃÂõûàwww-data. ÃÂÃÂþÃÂÃÂþ ú ýøü ñÃÂôõàþñÃÂðÃÂðÃÂÃÂÃÂàcgi-ÃÂÃÂõýðÃÂøù, ÃÂðñþÃÂðÃÂÃÂøù àÿÃÂðòðüø HTTP-ÃÂõÃÂòõÃÂð Apache, úþÃÂþÃÂÃÂù, ò ÃÂòþàþÃÂõÃÂõôÃÂ, øÃÂÿþûýÃÂõÃÂÃÂàþàøüõýø ôðýýþóþ ÿþûÃÂ÷þòðÃÂõûà[ò òðÃÂõü ôøÃÂÃÂÃÂøñÃÂÃÂøòõ þý üþöõàýð÷òðÃÂÃÂÃÂàÿþ-ôÃÂÃÂóþüÃÂ, â ÿÃÂøü. ÃÂõô.]. àPostgreSQL ÿþ ÃÂüþûÃÂðýøàÃÂÃÂõñÃÂõÃÂ, ÃÂÃÂþñàøüàÿþûÃÂ÷þòðÃÂõûàò ÃÂàÃÂþòÿðôðûþ àõóþ ÃÂøÃÂÃÂõüýÃÂü øüõýõü. ÃÂýõ ÃÂÃÂþ úðöõÃÂÃÂàôþÃÂÃÂðÃÂþÃÂýþ ÃÂôþñýÃÂü, ÃÂ
þÃÂàòÃÂ, úþýõÃÂýþ, üþöõÃÂõ ÿþÃÂÃÂÃÂÿøÃÂàÿþ-ÃÂòþõüÃÂ. | |
− | === DB API | + | === DB API ýð ÃÂÃÂÃÂðöõ ÃÂýøÃÂøúðÃÂøø === |
− | + | ÃÂÃÂÃÂðûþÃÂàÃÂð÷þñÃÂðÃÂÃÂÃÂÃÂ, úðú öõ Python ò÷ðøüþôõùÃÂÃÂòÃÂõààñð÷ðüø ôðýýÃÂÃÂ
. ÃÂûàÃÂÃÂþóþ Python ÿÃÂõôþÃÂÃÂðòûÃÂõàDB API â ÃÂÿõÃÂøðûÃÂýÃÂù øýÃÂõÃÂÃÂõùÃÂ, ÃÂýøÃÂøÃÂøÃÂÃÂÃÂÃÂøù ýðñþàüõÃÂþôþò, úþÃÂþÃÂÃÂõ ñÃÂôÃÂàþôøýðúþòþ ÃÂðñþÃÂðÃÂàýõ÷ðòøÃÂøüþ þàÃÂþóþ, àúðúþù áãÃÂàüàò÷ðøüþôõùÃÂÃÂòÃÂõü. ÃÂûàÃÂðñþÃÂààPostgreSQL ýðü ÿþýðôþñøÃÂÃÂàüþôÃÂûàPyPgSQL (ò ÃÂÃÂðýôðÃÂÃÂýþù ÿþÃÂÃÂðòúõ õóþ üþöõàýõ þúð÷ðÃÂÃÂÃÂÃÂ, ýþ òðàüõýõôöõàÿðúõÃÂþò ýðòõÃÂýÃÂúð ñÃÂôõàò úÃÂÃÂÃÂõ, úðú õóþ ÃÂÃÂÃÂðýþòøÃÂÃÂ; úÃÂÃÂðÃÂø, ÃÂÃÂþ ýõ õôøýÃÂÃÂòõýýÃÂù üþôÃÂûàâ àòðÃÂ, òþ÷üþöýþ, ñÃÂôõàPyGreSQL, úþÃÂþÃÂÃÂù ÃÂðñþÃÂðõàýøÃÂÃÂÃÂàýø ÃÂ
ÃÂöõ ø àÃÂõüø öõ ÃÂðüÃÂüø üõÃÂþôðüø). | |
− | DB API | + | DB API þÿÃÂõôõûÃÂõàÃÂÃÂðýôðÃÂÃÂýÃÂõ üõÃÂþôàÃÂðñþÃÂààñð÷ðüø ôðýýÃÂÃÂ
, ÃÂðú ÃÂÃÂþ, úðúþù ñàüþôÃÂûàòàýø ÷ðóÃÂÃÂ÷øûø ø àúðúþù ñàáãÃÂàýø ÃÂðñþÃÂðûø (ñÃÂôàÃÂþ MySQL, PostgreSQL, SQLite øûø ÃÂÃÂþ-ÃÂþ õÃÂõ), üõýÃÂÃÂÃÂÃÂàñÃÂôõàÃÂþûÃÂúþ øüàüþôÃÂûÃÂ. ÃÂûðòýþõ, ÃÂÃÂþñàøÃÂÿþûÃÂ÷ÃÂõüÃÂù üþôÃÂûàÃÂþþÃÂòõÃÂÃÂÃÂòþòðû DB API. àðÃÂÃÂüþÃÂÃÂøü úþÃÂþÃÂúþ þÃÂýþòýÃÂõ üõÃÂþôÃÂ: |
<source lang="python"> | <source lang="python"> | ||
Строка 119: | Строка 120: | ||
</source> | </source> | ||
− | + | âðú þÃÂÃÂÃÂõÃÂÃÂòûÃÂõÃÂÃÂàÿþôúûÃÂÃÂõýøõ ú ñð÷õ. à÷ðòøÃÂøüþÃÂÃÂø þàÃÂøÃÂÃÂðÃÂøø, òðü üþöõàÿþÃÂÃÂõñþòðÃÂÃÂÃÂàÃÂúð÷ðÃÂàÃÂþûÃÂúþ ýÃÂöýÃÂõ ÿðÃÂðüõÃÂÃÂà(ýðÿÃÂøüõÃÂ, øüàÃÂ
þÃÂÃÂð 'localhost' ÿþôÃÂð÷ÃÂüõòðõÃÂÃÂàÿþ ÃÂüþûÃÂðýøÃÂ). | |
<source lang="python"> | <source lang="python"> | ||
Строка 125: | Строка 126: | ||
</source> | </source> | ||
− | + | ÃÂÃÂÃÂÃÂþÃÂàÿþôôõÃÂöøòðÃÂÃÂÃÂàôðûõúþ ýõ òÃÂõüø áãÃÂÃÂ, ýþ ôûàþñÃÂýþÃÂÃÂø ò DB API þýø òòõôõýàø, ò ÃÂûÃÂÃÂðõ ýõþñÃÂ
þôøüþÃÂÃÂø, ôþûöýàÃÂüÃÂûøÃÂþòðÃÂÃÂÃÂàüþôÃÂûÃÂüø ÃÂþÿÃÂÃÂöõýøàøÃÂúÃÂÃÂÃÂÃÂòõýýþ. âðú ÃÂÃÂþ ýõ ÷ðñÃÂòðùÃÂõ þÃÂÿÃÂðòûÃÂÃÂàòÃÂõ òðÃÂø ÷ðÿÃÂþÃÂàÃÂõÃÂõ÷ úÃÂÃÂÃÂþÃÂ. | |
<source lang="python"> | <source lang="python"> | ||
Строка 131: | Строка 132: | ||
</source> | </source> | ||
− | + | âðú òÃÂÿþûýÃÂõÃÂÃÂàSQL-÷ðÿÃÂþÃÂ. ÃÂÃÂûø ò ÃÂÃÂÃÂþúõ ÷ðÿÃÂþÃÂð øÃÂÿþûÃÂ÷ÃÂÃÂÃÂÃÂà÷ýðúþüõÃÂÃÂð %s, ÃÂþ òÃÂþÃÂÃÂü ÿðÃÂðüõÃÂÃÂþü ÿõÃÂõôðõÃÂÃÂàÃÂÿøÃÂþú ÿõÃÂõüõýýÃÂÃÂ
-÷ýðÃÂõýøù, ÿÃÂøÃÂõü ò SQL-÷ðÿÃÂþÃÂõ ÷ýðúþüõÃÂÃÂð ýõ ÃÂÃÂõñÃÂõÃÂÃÂàþúÃÂÃÂöðÃÂàðÿþÃÂÃÂÃÂþÃÂðüø â üþôÃÂûàÃÂôõûðõàÃÂÃÂþ ÃÂðüþÃÂÃÂþÃÂÃÂõûÃÂýþ ò ÷ðòøÃÂøüþÃÂÃÂø þà| |
− | + | ÃÂøÿð ÿõÃÂõüõýýþù. | |
<source lang="python"> | <source lang="python"> | ||
Строка 138: | Строка 139: | ||
</source> | </source> | ||
− | + | ÃÂþ÷òÃÂðÃÂðõàôòÃÂüõÃÂýÃÂù ÃÂÿøÃÂþú (ÃÂÃÂÃÂþúø â ÿþûÃÂ) ÿþûÃÂÃÂõýýÃÂÃÂ
þàáãÃÂàôðýýÃÂÃÂ
. áÃÂÃÂõÃÂÃÂòÃÂÃÂàø ôÃÂÃÂóøõ üõÃÂþôÃÂ, þ÷ýðúþüøÃÂÃÂÃÂààúþÃÂþÃÂÃÂüø òàÃÂüþöõÃÂõ ò ôþúÃÂüõýÃÂðÃÂøø øûø àÿþüþÃÂÃÂà÷ýðúþüþù òðü ÃÂÃÂýúÃÂøø dir() ôð ÿðÃÂÃÂ-ÃÂÃÂþùúø ýõÃÂûþöýÃÂÃÂ
ÃÂúÃÂÿõÃÂøüõýÃÂþò. | |
− | === | + | === ÃÂðúÃÂõÿûÃÂõü ýð ÿÃÂðúÃÂøúõ === |
− | + | ÃÂõÃÂõùôõü ú ÃÂðÃÂÃÂüþÃÂÃÂõýøàýðÃÂõóþ ÿÃÂøüõÃÂð. ÃÂðÃÂýõü ÃÂÃÂðýôðÃÂÃÂýþ â ÃÂúðöõü úþôøÃÂþòúÃÂ, ÿþôúûÃÂÃÂøü ýÃÂöýÃÂõ üþôÃÂûø: | |
<source lang="python"> | <source lang="python"> | ||
Строка 150: | Строка 151: | ||
</source> | </source> | ||
− | + | ÃÂðûõõ, þÿÃÂõôõûøü ôòõ ÃÂÃÂýúÃÂøø. ÃÂõÃÂòðàñÃÂôõàþÃÂòõÃÂðÃÂà÷ð ôþñðòûõýøõ ýþòþóþ ÃÂþþñÃÂõýøàò ñð÷ÃÂ: | |
<source lang="python"> | <source lang="python"> | ||
Строка 164: | Строка 165: | ||
</source> | </source> | ||
− | + | ÃÂðú òøôøÃÂõ, òÃÂõ þÃÂõýàôðöõ ûþóøÃÂýþ: ÃÂÃÂÃÂðýðòûøòðõü ÃÂþõôøýõýøõ àÃÂà(ÿþÃÂúþûÃÂúàò ýðÃÂõü ÃÂûÃÂÃÂðõ ÿþôúûÃÂÃÂõýøõ òÃÂÿþûýÃÂõÃÂÃÂààøüõýõü ÃÂõúÃÂÃÂõóþ ÃÂøÃÂÃÂõüýþóþ ÿþûÃÂ÷þòðÃÂõûÃÂ, ÃÂþ ôþÃÂÃÂðÃÂþÃÂýþ ÃÂúð÷ðÃÂàÃÂþûÃÂúþ øüàñð÷ÃÂ), ÃÂþ÷ôðõü úÃÂÃÂÃÂþà(ò PostgreSQL þýø ýõ ÿÃÂøüõýÃÂÃÂÃÂÃÂÃÂ, ýþ þýø ÃÂüÃÂûøÃÂÃÂÃÂÃÂÃÂàúðöôÃÂü üþôÃÂûõü, ÿÃÂõÃÂõýôÃÂÃÂÃÂøü ýð ÃÂþþÃÂòõÃÂÃÂÃÂòøõ DB API), òÃÂÿþûýÃÂõÃÂÃÂà÷ðÿÃÂþÃÂ, ÷ðúÃÂÃÂòðõÃÂÃÂàúÃÂÃÂÃÂþÃÂ, ÃÂøúÃÂøÃÂÃÂÃÂÃÂÃÂàø÷üõýõýøà(PostgreSQL øÃÂÿþûÃÂ÷ÃÂõàÃÂÃÂðý÷ðúÃÂøø, ÿþÃÂÃÂþüàòÃÂÿþûýõýøõ üõÃÂþôð commit() þñÃÂ÷ðÃÂõûÃÂýþ, øýðÃÂõ òðÃÂø ø÷üõýõýøàýõ ñÃÂôÃÂàÃÂþÃÂ
ÃÂðýõýÃÂ), ø, ýðúþýõÃÂ, ÷ðúÃÂÃÂòðõü ÃÂðüþ ÃÂþõôøýõýøõ àñð÷þù. àÿþûõ datum ÷ðýþÃÂøü ÷ýðÃÂõýøõ òÃÂÃÂÃÂþõýýþù ÿõÃÂõüõýýþù PostgreSQL â now, úþÃÂþÃÂðàúðöôÃÂù ÃÂð÷ ÷ðüõýÃÂõÃÂÃÂàÃÂõúÃÂÃÂøü ÷ýðÃÂõýøõü ôðÃÂàø òÃÂõüõýø. | |
− | + | ÃÂàø ÿõÃÂðÃÂà÷ðóþûþòúð ëLocationû òÃÂÿþûýÃÂõÃÂÃÂàôûàÃÂþóþ, ÃÂÃÂþñàÿõÃÂõýðÿÃÂðòøÃÂàÿþûÃÂ÷þòðÃÂõûàýð ÃÂÃÂþàöõ ÃÂÃÂõýðÃÂøù, ýþ ÃÂöõ ñõ÷ ÿðÃÂðüõÃÂÃÂþò â üàöõ ôþûöýàÿþúð÷ðÃÂàúûøõýÃÂÃÂ, ÃÂÃÂþ þý ýð ÃÂðüþü ôõûõ òòõû? (ïúþÃÂà#form øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂÃÂ, ÃÂÃÂþñàðòÃÂþüðÃÂøÃÂõÃÂúø ÿÃÂþúÃÂÃÂÃÂøÃÂàÃÂÃÂÃÂðýøÃÂúàýð ÿþÃÂûõôýõõ ÃÂþþñÃÂõýøõ). | |
− | + | ÃÂÃÂþÃÂðàÃÂÃÂýúÃÂøàñÃÂôõàþÃÂòõÃÂðÃÂà÷ð òÃÂòþô ýð ÃÂúÃÂðý ÃÂöõ þÃÂÃÂðòûõýýÃÂÃÂ
ò úýøóõ ÷ðÿøÃÂõù, ð ÃÂðúöõ ÷ð ÃÂþÃÂüÃÂ, àÿþüþÃÂÃÂàúþÃÂþÃÂþù üþöýþ ñÃÂôõàôþñðòøÃÂàø ÃÂòþõ òÃÂÃÂúð÷ÃÂòðýøõ: | |
<source lang="python"> | <source lang="python"> | ||
Строка 180: | Строка 181: | ||
</source> | </source> | ||
− | + | àÃÂÃÂþü ÃÂÃÂðóüõýÃÂõ üàòÃÂñøÃÂðõü òÃÂõ ÃÂÃÂÃÂþúø ø÷ ýðÃÂõù ÃÂðñûøÃÂàôðýýÃÂÃÂ
, ÃÂþÃÂÃÂøÃÂÃÂàøÃÂ
ÿþ ôðÃÂõ. àõ÷ÃÂûÃÂÃÂðàÃÂþÃÂ
ÃÂðýÃÂõÃÂÃÂàò ÿõÃÂõüõýýþù res, àúþÃÂþÃÂþù ø ñÃÂôõü ÃÂðñþÃÂðÃÂÃÂ. âõÿõÃÂàþÃÂÃÂðûþÃÂàûøÃÂàðúúÃÂÃÂðÃÂýõýÃÂúþ ÃÂð÷ûþöøÃÂàýðÃÂø ôðýýÃÂõ ÿþ ÃÂðñûøÃÂúðü ø òÃÂòõÃÂÃÂø øÃÂ
ýð ÃÂúÃÂðý: | |
<source lang="python"> | <source lang="python"> | ||
print "Content-Type: text/html\n" | print "Content-Type: text/html\n" | ||
− | print "<H1 style='color:#7777FF'><U> | + | print "<H1 style='color:#7777FF'><U>ÃÂõûÃÂúðü ú ýðü ò óþÃÂÃÂø!</U></H1>" |
for item in res: | for item in res: | ||
print """<TABLE width='90%%'> | print """<TABLE width='90%%'> | ||
− | <TR><TD><SMALL> | + | <TR><TD><SMALL>âþòðÃÂøà<B>%s</B> ÿþòõôðûýðü ÃÂûõôÃÂÃÂÃÂõõ:</SMALL> |
<TD align='right'><SMALL>%s</SMALL> | <TD align='right'><SMALL>%s</SMALL> | ||
<TR><TD style='background-color:#DDDDFF' colspan='2'>%s | <TR><TD style='background-color:#DDDDFF' colspan='2'>%s | ||
</TABLE>""" % (item[1], str(item[0])[:19], item[2]) | </TABLE>""" % (item[1], str(item[0])[:19], item[2]) | ||
− | print "<HR><A name='form'><H3> | + | print "<HR><A name='form'><H3>ÃÂÃÂøÃÂþõôøýÃÂùÃÂõÃÂàú ôøÃÂúÃÂÃÂÃÂøø:</H3>" |
print """<FORM method='GET'> | print """<FORM method='GET'> | ||
− | + | ÃÂðÃÂõ øüÃÂ: <INPUT type='text' name='author'><BR> | |
− | + | çÃÂþ òàôÃÂüðõÃÂõ ÿþ ÃÂÃÂþüàÿþòþôÃÂ:<BR> | |
<TEXTAREA name='message' rows='5' cols='80'></TEXTAREA><BR> | <TEXTAREA name='message' rows='5' cols='80'></TEXTAREA><BR> | ||
− | <INPUT type='submit' value=' | + | <INPUT type='submit' value='ÃÂÃÂÿÃÂðòøÃÂÃÂ'> |
</FORM>""" | </FORM>""" | ||
</source> | </source> | ||
<div id="img"></div> | <div id="img"></div> | ||
− | [[ | + | [[ÃÂ÷þñÃÂðöõýøõ:Img 83 81 1.png|thumb|ÃÂø ÃÂüðùûøúþò, ýø BB-úþôð, ýø ôðöõ ûþóþÃÂøÿð... ÃÂðÃÂþ üàÃÂôõûðûø ÃÂÃÂàóþÃÂÃÂõòÃÂà÷ð 10 üøýÃÂÃÂ!]] |
− | + | áüÃÂÃÂû úþýÃÂÃÂÃÂÃÂúÃÂøø str(item[0])[:19] ÷ðúûÃÂÃÂðõÃÂÃÂàò ÃÂþü, ÃÂÃÂþñàò ÃÂÃÂÃÂþúõ òÃÂõüõýø þÃÂÃÂõÃÂàýõýÃÂöýÃÂõ ýðü üøûûøÃÂõúÃÂýôÃÂ, úþÃÂþÃÂÃÂõ ÃÂþÃÂ
ÃÂðýÃÂÃÂÃÂÃÂàò ÿþûõ ÃÂøÿð timestamp. ÃÂþÃÂûõ òÃÂõÃÂ
þÿÃÂñûøúþòðýýÃÂÃÂ
ÃÂþþñÃÂõýøù òÃÂòþôøü ÃÂþÃÂüàôþñðòûõýøàýþòþóþ, ÃÂÃÂþñàúðöôÃÂù üþó ÿÃÂøÃÂþõôøýøÃÂÃÂÃÂàú ýðÃÂõù ôøÃÂúÃÂÃÂÃÂøø. ÃÂÃÂÃÂðÃÂø, ò ÃÂõóõ <FORM> üàýõ ÃÂúð÷ðûø ÿðÃÂðüõÃÂàaction, ÿþÃÂúþûÃÂúàôðýýÃÂõ ñÃÂôÃÂàÿõÃÂõôðòðÃÂÃÂÃÂàýð þñÃÂðñþÃÂúàÃÂÃÂþüàöõ ÃÂÃÂõýðÃÂøà(ñûðóþôðÃÂàÃÂõüàøüàÃÂÃÂõýðÃÂøàüþöýþ ÿÃÂøÃÂòþøÃÂàûÃÂñþõ). | |
− | + | ÃÂðúþýõÃÂ, ÿþÃÂûõôýøù ÃÂÃÂðóüõýÃÂ: | |
<source lang="python"> | <source lang="python"> | ||
Строка 217: | Строка 218: | ||
</source> | </source> | ||
− | + | áþ÷ôðõü FieldStorage-þñÃÂõúÃÂ, ø õÃÂûø ò ýõü õÃÂÃÂà÷ðÿþûýõýýÃÂõ ÿþûàmessage ø author (ÃÂþ õÃÂÃÂà÷ðÿÃÂþàñÃÂû ÃÂÃÂþÃÂüøÃÂþòðý ø÷ ÷ðÿþûýõýýþù ÿþûÃÂ÷þòðÃÂõûõü ÃÂþÃÂüÃÂ), ÃÂþ, ýõüýþöúþ øÃÂ
þñÃÂðñþÃÂðò (ÃÂÃÂýúÃÂøàcgi.escape() ÷ðüõýÃÂõàòÃÂõ ëýõñûðóþýðôõöýÃÂõû ÃÂøüòþûàâ ýðÿÃÂøüõÃÂ, < â øÃÂ
ÃÂÃÂðýôðÃÂÃÂýÃÂüø SGML-ÃÂÃÂÃÂýþÃÂÃÂÃÂüø, ò ôðýýþü ÃÂûÃÂÃÂðõ â <), ÿõÃÂõôðõü ÃÂÃÂýúÃÂøø addMessage(). ÃÂñÃÂðñþÃÂúð ýÃÂöýð ôûàÃÂþóþ, ÃÂÃÂþñà÷ûþÃÂüÃÂÃÂûõýýøú ýõ üþó òòõÃÂÃÂø ò ÿþûõ ÃÂþþñÃÂõýøàøûø øüõýø ðòÃÂþÃÂð ÃÂÃÂþ-ýøñÃÂôàÃÂðúþõ: | |
− | <SCRIPT>alert(' | + | <SCRIPT>alert('ÃÂð ÿþÃÂûø òàòÃÂõ!');</SCRIPT> |
− | + | àÃÂûþòÃÂ, ÿÃÂõýõñÃÂõóðÃÂàÿÃÂþòõÃÂúþù òòõôõýýÃÂÃÂ
ôðýýÃÂÃÂ
ýø ò úþõü ÃÂûÃÂÃÂðõ ýõûÃÂ÷ÃÂ. ÃÂðùôøÃÂõ úðú-ýøñÃÂôàýð [http://securitylab.ru securitylab.ru] ø ÿþÃÂüþÃÂÃÂøÃÂõ, ÃÂúþûÃÂúþ ÃÂÃÂ÷òøüþÃÂÃÂõù ÃÂøÿð ëXSSû þñýðÃÂÃÂöøòðõÃÂÃÂàúðöôÃÂù üõÃÂÃÂÃÂ! âðú ÃÂÃÂþ ÃÂÃÂÃÂúø ÃÂÃÂÃÂúðüø, ýþ ÿþÃÂûõôÃÂÃÂòøàüþóÃÂàñÃÂÃÂàþÃÂõýàÃÂõÃÂÃÂõ÷ýÃÂüø. | |
− | === | + | === ÃÂÃÂôð öõ ýðü ÃÂõÿõÃÂàøôÃÂø? === |
− | + | ÃÂÃÂðú, ÃÂÃÂþ-ÃÂþ òÿþûýõ ÃÂðñþÃÂþÃÂÿþÃÂþñýþõ àýðàõÃÂÃÂà(ÃÂü. [[LXF83:Python#img|ÃÂøÃÂÃÂýþú]]). ÃÂþ úðú òàüþöõàôþóðôðÃÂÃÂÃÂÃÂ, ýðÃÂð óþÃÂÃÂõòðàþÃÂõýàôðûõúð þàÃÂþòõÃÂÃÂõýÃÂÃÂòð. çÃÂþ õÃÂõ üþöýþ ÃÂôõûðÃÂÃÂ? ÃÂÃÂ, ýðÿÃÂøüõÃÂ, ÃÂð÷ñøÃÂàýð ÃÂÃÂÃÂðýøÃÂÃÂ. ÃÂþúð ÃÂþþñÃÂõýøù ò ýõù ñÃÂôõàýõ ñþûÃÂÃÂõ ôÃÂöøýÃÂ, ÃÂþùôõàø ÃÂðú. àúþóôð øÃÂ
ÃÂøÃÂûþ ôþùôõàôþ ÃÂþÃÂýø, ÃÂþ ÃÂõôúøù ÿþûÃÂ÷þòðÃÂõûàôþöôõÃÂÃÂàþúþýÃÂðýøà÷ðóÃÂÃÂ÷úø òÃÂõÃÂ
ôðýýÃÂÃÂ
. ÃÂþöýþ ôðÃÂàÿþûÃÂ÷þòðÃÂõûÃÂü òþ÷üþöýþÃÂÃÂàøÃÂÿþûÃÂ÷þòðÃÂàýõúþÃÂþÃÂÃÂõ HTML-ÃÂõóø, ÃÂÃÂþñàøÃÂ
ÃÂþþñÃÂõýøàòÃÂóûÃÂôõûø ñþûõõ úÃÂðÃÂþÃÂýþ. ÃÂþöýþ ôþñðòøÃÂàÃÂüðùûøúþò... àüþöýþ ôðöõ ÃÂôõûðÃÂàüþôÃÂûàðôüøýøÃÂÃÂÃÂøÃÂþòðýøÃÂ, ÿþ÷òþûÃÂÃÂÃÂøù ÃÂõôðúÃÂøÃÂþòðÃÂàøûø ÃÂôðûÃÂÃÂàÃÂþþñÃÂõýøÃÂ, ð ÃÂðúöõ þÃÂòõÃÂðÃÂàýð ýøÃÂ
. âðú ÃÂÃÂþ ÃÂðñþÃÂàýõÿþÃÂðÃÂÃÂù úÃÂðù. ÃÂõÃÂ÷ðùÃÂõ â ýõ ñÃÂôàòðü üõÃÂðÃÂÃÂ. | |
− | === | + | === ÃÂõúþÃÂþÃÂÃÂõ ÃÂðÃÂÿÃÂþÃÂÃÂÃÂðýÃÂýýÃÂõ MIME-ÃÂøÿà=== |
{| style="background:white;color:black;" border="1" cellspacing="0" | {| style="background:white;color:black;" border="1" cellspacing="0" | ||
|- style="background:#dfcfe6;color:black" | |- style="background:#dfcfe6;color:black" | ||
− | ! MIME- | + | ! MIME-ÃÂøÿ |
− | ! | + | ! ÃÂÿøÃÂðýøõ |
|- | |- | ||
| text/plain | | text/plain | ||
− | | | + | | ÃÂÃÂþÃÂÃÂþù ÃÂõúÃÂà|
|- | |- | ||
| text/html | | text/html | ||
− | | HTML- | + | | HTML-ÃÂÃÂÃÂðýøÃÂð |
|- | |- | ||
| image/gif | | image/gif | ||
− | | | + | | ÃÂ÷þñÃÂðöõýøõ GIF |
|- | |- | ||
| video/mpeg | | video/mpeg | ||
− | | | + | | ÃÂøôõþ-ÃÂðùû ò ÃÂþÃÂüðÃÂõ MPEG |
|- | |- | ||
| application/msword | | application/msword | ||
− | | | + | | ÃÂþúÃÂüõýàMS Word |
|} | |} |
Версия 08:32, 28 мая 2009
|
|
|
[http://s1.shard.jp/galeach/new77.html erbasia ] [http://s1.shard.jp/olharder/comparatif-automobile.html plane trains and automobile quote ] [http://s1.shard.jp/olharder/auto-bill-fitts.html autoharp recording ] [http://s1.shard.jp/losaul/teds-camera-australia.html australia c cure cure hepatitis in ] [http://s1.shard.jp/losaul/online-computer.html deadly spiders australia ] map [http://s1.shard.jp/losaul/murrays-buses.html australian daylight saving time changes ] [http://s1.shard.jp/bireba/norton-antivirus.html mcfee antivirus updates ] [http://s1.shard.jp/galeach/new159.html multiple endocrine neoplasias ] [http://s1.shard.jp/frhorton/ank33l6la.html kalulu south africa ] [http://s1.shard.jp/bireba/2005-antivirus.html pc world antivirus reviews ] [http://s1.shard.jp/galeach/new49.html new york asian escort incall ] [http://s1.shard.jp/olharder/automobile-accident.html automobile dealer dodge part ] grisoft antivirus free download links [http://s1.shard.jp/bireba/mobile-antivirus.html winantivirus pro 2005 download ] [http://s1.shard.jp/bireba/download-antivirus.html av antivirus free ] [http://s1.shard.jp/olharder/the-autobiography.html automobile loans rates ] [http://s1.shard.jp/galeach/new127.html quality asian page ] [http://s1.shard.jp/olharder/automobile-computer.html west virginia auto auctions ] [http://s1.shard.jp/bireba/antivirus-comparison.html symantec corporate antivirus ] [http://s1.shard.jp/galeach/new88.html asian hair male style ] anderson autopsy lee martin [http://s1.shard.jp/olharder/auto-club-country.html browning automatic pistols ] [http://s1.shard.jp/bireba/how-to-activate.html mac affee antivirus ] [http://s1.shard.jp/galeach/new167.html asian american family counseling center houston ] index [http://s1.shard.jp/olharder/automatic-dc-queue.html autoweekly.com ] [http://s1.shard.jp/bireba/quickheal-antivirus.html panda antivirus online scan ] [http://s1.shard.jp/olharder/autonomy-principal.html autoloc power antenna instructions ] url [http://s1.shard.jp/bireba/antivirus-cd.html abg antivirus free download ] domain [http://s1.shard.jp/bireba/removing-norton.html uninstall norton antivirus corporate ] [http://s1.shard.jp/frhorton/4klamxahb.html africa photography ] [http://s1.shard.jp/bireba/antivirus-2004-download.html norton free antivirus software ] [http://s1.shard.jp/bireba/avg-free-download.html grisofts avg antivirus ] [http://s1.shard.jp/olharder/johnny-bench.html autobiography of antwone fisher ] south african myths [http://s1.shard.jp/galeach/new51.html mr. chews asian beaver mika ] [http://s1.shard.jp/losaul/car-importers-australia.html mining contractors australia ] [http://s1.shard.jp/galeach/new20.html asian journalist ] [http://s1.shard.jp/bireba/eztrust-antivirus.html mcafee antivirus 2005 download ] [http://s1.shard.jp/bireba/symantec-antivirus.html antivirus software review cnet ] [http://s1.shard.jp/galeach/new112.html cortical dysplasia ] [http://s1.shard.jp/galeach/new94.html walt disney's fantasia ] [http://s1.shard.jp/losaul/australia-importing.html australia coast gold shark ] link [http://s1.shard.jp/losaul/australian-photography.html australia fishing championship ] [http://s1.shard.jp/frhorton/ru9zwzdr5.html provincial map of south africa ] [http://s1.shard.jp/frhorton/7bbhgy4dh.html african chritianity culture mugambi ] http [http://s1.shard.jp/losaul/epoxy-surfboards.html australia in repurchases share ] [http://s1.shard.jp/galeach/new57.html american asian festival film jose san ] [http://s1.shard.jp/olharder/bxautozip.html automovel de loja ] [http://s1.shard.jp/galeach/new4.html deloitte technology fast 500 asia pacific ] [http://s1.shard.jp/losaul/music-therapy-courses.html itil australia ] [http://s1.shard.jp/losaul/mudgee-australia.html talbot victoria australia ] [http://s1.shard.jp/losaul/australia-next.html lone fathers association australia ] map url africa history togo [http://s1.shard.jp/losaul/australia-british.html the court system in australia ] [http://s1.shard.jp/bireba/notan-antivirus.html pandaantivirusonline ] [http://s1.shard.jp/galeach/new172.html asian american student ] [http://s1.shard.jp/bireba/alertas-antivirus.html network antivirus scanner ] [http://s1.shard.jp/galeach/new148.html euthanasia mercy killing ] [http://s1.shard.jp/bireba/top-ten-antivirus.html uninstall norton antivirus corporate ] page [http://s1.shard.jp/losaul/australia-immigration.html athetics australia ] rolling stones australian releases link http [http://s1.shard.jp/losaul/police-federation.html ball dresses australia ] anderson autopsy lee martin [http://s1.shard.jp/olharder/1-800-safe-auto.html volvo auto repair garage ] link [http://s1.shard.jp/bireba/downloads-antivirus.html antivirus checkup ] [http://s1.shard.jp/losaul/department-of-agriculture.html australia free holiday ] [http://s1.shard.jp/olharder/luggage-rack-automobile.html prays auto ] [http://s1.shard.jp/losaul/western-plains.html australia immigration government ] [http://s1.shard.jp/bireba/norton-antivirus.html symantec antivirus server port ] [http://s1.shard.jp/galeach/new158.html public opinion on euthanasia ] [http://s1.shard.jp/bireba/map.html norton antivirus free download full version ] [http://s1.shard.jp/olharder/autocad-2005-serial.html auto collection ford land lincoln quebec rover ] http [http://s1.shard.jp/frhorton/smui5er3r.html south africa sports tv ] [http://s1.shard.jp/galeach/new16.html asian teen for cash ] [http://s1.shard.jp/bireba/norton-antivirus.html ad ware antivirus ] [http://s1.shard.jp/olharder/subasta-de-autos.html reedman toll auto world langhorne pa ] [http://s1.shard.jp/galeach/new101.html tales of phantasia ova ] sitemap [http://s1.shard.jp/olharder/auto-insurance.html bosch auto air filter ] [http://s1.shard.jp/frhorton/xntk9qgnd.html medical association of south africa ] [http://s1.shard.jp/losaul/australia-from.html pt cruisers australia ] [http://s1.shard.jp/frhorton/lmi1tnyfh.html wwii north africa battles ] [http://s1.shard.jp/bireba/antivirus-software.html avg antivirus reviews ] Шаблон:æøúû/Python
àðñþÃÂð àñð÷ðüø ôðýýÃÂàø web-ÿÃÂþóÃÂðüüøÃÂþòðýøõ
çðÃÂÃÂà3 çÃÂþ üþöõàñÃÂÃÂàüþÃÂýõõ ÃÂòÃÂ÷úø ëñð÷ð ôðýýÃÂà+ øýÃÂõÃÂýõÃÂû? àõÃÂûø ú ÃÂÃÂþüàôþñðòøÃÂàõÃÂõ ø Python... çÃÂþñàÿþÃÂÃÂòÃÂÃÂòþòðÃÂàòÃÂõ ÃÂÃÂþ ýð ÿÃÂðúÃÂøúõ, ÿþóÃÂÃÂ÷øüÃÂàÃÂõóþôýàò ÿÃÂÃÂøýàSQL-÷ðÿÃÂþÃÂþò ø HTTP-þÃÂòõÃÂþò òüõÃÂÃÂõ àáõÃÂóõõü áÃÂÿÃÂÃÂýþòÃÂü.
ÃÂàÃÂöõ òøôõûø, ÃÂÃÂþ Python ÿÃÂõúÃÂðÃÂýþ ÿþôàþôøàôûàÃÂðñþÃÂààÃÂõúÃÂÃÂþü. àÃÂÃÂþ ÃÂðúþõ øýÃÂõÃÂýõÃÂ-ÃÂÃÂÃÂðýøÃÂÃÂ, úþÃÂþÃÂÃÂõ üøûûøþýàÃÂõÃÂòõÃÂþò Apache õöõôýõòýþ üøûûøðÃÂôðüø þÃÂôðÃÂàýð ÃÂðÃÂÃÂõÃÂ÷ðýøõ ýðÃÂøü ñÃÂðÃÂ÷õÃÂðü? ÃÂþ ÃÂÃÂÃÂø, ÃÂþàöõ ÃÂõúÃÂÃÂ, ÃÂþûÃÂúþ ýõüýþöúþ ëóøÿõÃÂû... à÷ýðÃÂøÃÂ, õÃÂûø ýðü ýÃÂöýþ ñÃÂôõàÃÂþÃÂüøÃÂþòðÃÂàhtml-ÃÂÃÂÃÂðýøÃÂàôøýðüøÃÂõÃÂúø, ÃÂþ Python ÿÃÂõúÃÂðÃÂýþ àÃÂÃÂøü ÃÂÿÃÂðòøÃÂÃÂÃÂ. àýøúðúøàÿÃÂõÿÃÂÃÂÃÂÃÂòøù ôûàÃÂð÷ÃÂðñþÃÂúø ýð ýõü CGI-ÃÂÃÂõýðÃÂøõò ýõ ÃÂÃÂÃÂõÃÂÃÂòÃÂõàâ web-ÃÂõÃÂòõÃÂÃÂ, ÿþ ñþûÃÂÃÂþüàÃÂÃÂõÃÂÃÂ, ñõ÷ÃÂð÷ûøÃÂýþ, úðú øüõýýþ òÃÂÿþûýÃÂõÃÂÃÂàÃÂúÃÂøÿàø ýð úðúþü ÃÂ÷ÃÂúõ þý ÃÂð÷ÃÂðñþÃÂðý: ûøÃÂàñàþý ÃÂüõû ÃÂøÃÂðÃÂàôðýýÃÂõ ø÷ ÿþÃÂþúð òòþôð ø ÿõÃÂõüõýýÃÂàþúÃÂÃÂöõýøàôð þÃÂôðòðÃÂàÃÂõúÃÂàò ÃÂÃÂðýôðÃÂÃÂýÃÂù òÃÂàþôýþù ÿþÃÂþú.
ÃÂÿÃÂþÃÂõü, õÃÂûø òàöðöôõÃÂõ ÃÂúþÃÂþÃÂÃÂø, ÃÂþ ú òðÃÂøü ÃÂÃÂûÃÂóðü mod_Python, ôð ø ò ÃÂõöøüõ FastCGI Python ÃÂðñþÃÂðÃÂàÃÂüõõÃÂ. ÃÂþ ÃÂõùÃÂðààýðàÃÂð÷óþòþàòÃÂõ öõ ýõ þ ýðÃÂÃÂÃÂþùúðàCGI, ð þ Python, ÃÂðú ÃÂÃÂþ òõÃÂýõüÃÂàú ÃÂþüÃÂ, ÃÂðôø ÃÂõóþ üàÃÂÃÂàÃÂÃÂðÃÂÃÂàýðÃÂðûø.
ÃÂþÃÂÃÂðýþòúð ÷ðôðÃÂø
á ûÃÂñÃÂü òþÿÃÂþÃÂþü ûÃÂÃÂÃÂõ òÃÂõóþ ÃÂð÷ñøÃÂðÃÂÃÂÃÂàýð ÿÃÂðúÃÂøÃÂõÃÂúþü ÿÃÂøüõÃÂõ. ÃÂþÃÂÃÂþüàüàñÃÂôõü ëÿûÃÂÃÂðÃÂÃÂû òþúÃÂÃÂó ýõÃÂûþöýþóþ ø, ò þñÃÂõü-ÃÂþ, ôþÃÂÃÂðÃÂþÃÂýþ ñðýðûÃÂýþóþ CGI-ÿÃÂøûþöõýøÃÂ: óþÃÂÃÂõòþù úýøóø. ÃÂðþôýþ ÃÂð÷ñõÃÂõüÃÂààÃÂõü, úðú Python ò÷ðøüþôõùÃÂÃÂòÃÂõààñð÷ðüø ôðýýÃÂà, óôõ ÿÃÂõôÃÂÃÂðòûÃÂõÃÂÃÂàÃÂð÷ÃÂüýÃÂü àÃÂðýøÃÂàòÃÂõ ýðÃÂø ÃÂþþñÃÂõýøÃÂ.
ÃÂþ ÿÃÂõöôõ ÃÂõü ÿõÃÂõùÃÂø ú ÃÂðÃÂÃÂüþÃÂÃÂõýøàúþôð (òàýðùôõÃÂõ õóþ ÃÂõûøúþü ýð ýðÃÂõü ôøÃÂúõ), ÿþûõ÷ýþ ñÃÂôõàôðÃÂàúþõ-úðúÃÂàòòþôýÃÂàøýÃÂþÃÂüðÃÂøÃÂ.
ãýøòõÃÂÃÂðûÃÂýþõ ëüõöôÃÂüþÃÂôÃÂõû CGI
CGI (Common Gateway Interface, þñÃÂøù ÃÂûÃÂ÷þòþù øýÃÂõÃÂÃÂõùÃÂ) ñÃÂû ÃÂð÷ÃÂðñþÃÂðý úðú ÃÂÃÂõôÃÂÃÂòþ ò÷ðøüþôõùÃÂÃÂòøàHTTP-ÃÂõÃÂòõÃÂð àÿÃÂþóÃÂðüüðüø, úþÃÂþÃÂÃÂõ üþóÃÂà÷ðÿÃÂÃÂúðÃÂÃÂÃÂàò þÿõÃÂðÃÂøþýýþù ÃÂøÃÂÃÂõüõ. ÃÂÃÂûø óþòþÃÂøÃÂàÃÂÿÃÂþÃÂõýýþ, ÃÂþ CGI, ÿõÃÂõôðòðàÃÂÿÃÂðòûõýøõ ÃÂðúþù ÿÃÂþóÃÂðüüõ (þñÃÂÃÂýþ øàøüõýÃÂÃÂàcgi-ÃÂÃÂõýðÃÂøÃÂüø, àþÃÂàÃÂÃÂþ òÿþûýõ üþöõàñÃÂÃÂàø ôòþøÃÂýÃÂù ÃÂðùû, ÃÂð÷ÃÂðñþÃÂðýýÃÂù ýð C/C++), ÃÂþÃÂüøÃÂÃÂõàôûàýõõ þÿÃÂõôõûõýýþõ þúÃÂÃÂöõýøõ. àÃÂðÃÂÃÂýþÃÂÃÂø, ÿðÃÂðüõÃÂÃÂàHTTP-÷ðÿÃÂþÃÂð, ÿþûÃÂÃÂõýýþóþ þàúûøõýÃÂð, üþóÃÂàÿþüõÃÂðÃÂÃÂÃÂàò þÿÃÂõôõûõýýÃÂõ ÿõÃÂõüõýýÃÂõ þúÃÂÃÂöõýøàøûø ÿõÃÂõôðòðÃÂÃÂÃÂàcgi-ÿÃÂþóÃÂðüüõ úðú ðÃÂóÃÂüõýÃÂàøûø úðú òàþôýþù ÿþÃÂþú (STDIN). àþÃÂòõàHTTP-ÃÂõÃÂòõàöôõàôðýýÃÂõ, úþÃÂþÃÂÃÂõ cgi-ÿÃÂþóÃÂðüüð ôþûöýð òÃÂôðÃÂàò ÃÂÃÂðýôðÃÂÃÂýÃÂù òÃÂàþôýþù ÿþÃÂþú (STDOUT), ø ÿõÃÂõôðõàøàúûøõýÃÂÃÂ.
âðúøü þñÃÂð÷þü, òÃÂõ, ÃÂÃÂþ ÃÂÃÂõñÃÂõÃÂÃÂàþàcgi-ÿÃÂþóÃÂðüüÃÂ, ÃÂÃÂþ ÃÂÿþÃÂþñýþÃÂÃÂàÿþûÃÂÃÂðÃÂàýõþñàþôøüÃÂàôûàÃÂðñþÃÂàøýÃÂþÃÂüðÃÂøàø÷ ÃÂþÃÂüøÃÂÃÂõüþù HTTP-ÃÂõÃÂòõÃÂþü ÃÂÃÂõôàø òþ÷òÃÂðÃÂðÃÂàþÃÂòõÃÂýÃÂõ ôðýýÃÂõ, ÃÂþþÃÂòõÃÂÃÂÃÂòÃÂÃÂÃÂøõ ÿÃÂþÃÂþúþûàHTTP, ÃÂÃÂþñàweb-úûøõýà÷ýðû, ÃÂÃÂþ àýøüø ôõûðÃÂÃÂ.
ãÃÂøüÃÂàÿþÃÂÃÂûðÃÂÃÂ
ÃÂðÃÂýõü àÃÂþÃÂüøÃÂþòðýøàHTTP-þÃÂòõÃÂð. çÃÂþñàñÃÂðÃÂ÷õàúûøõýÃÂð üþó õóþ ÿÃÂðòøûÃÂýþ þñÃÂðñþÃÂðÃÂÃÂ, þý ôþûöõý ÃÂþÃÂÃÂþÃÂÃÂàø÷ ÷ðóþûþòúð ø ÃÂõûð, ÃÂð÷ôõûõýýÃÂàÿÃÂÃÂÃÂþù ÃÂÃÂÃÂþúþù. à÷ðóþûþòúõ ÿõÃÂõôðõÃÂÃÂàýõþñàþôøüðàÃÂûÃÂöõñýðàøýÃÂþÃÂüðÃÂøÃÂ, ýðÿÃÂøüõÃÂ, ÃÂøÿ ÃÂþôõÃÂöøüþóþ, õóþ úþôøÃÂþòúð, ÃÂúð÷ðýøõ ñÃÂðÃÂ÷õÃÂà÷ðÿÃÂþÃÂøÃÂàôÃÂÃÂóþù ÃÂõÃÂÃÂÃÂà(ÃÂðú ýð÷ÃÂòðõüþõ ÿõÃÂõýðÿÃÂðòûõýøõ), ø ÃÂ.ô. ÃÂÃÂþÃÂÃÂõùÃÂøù cgi-ÃÂÃÂõýðÃÂøù ýð ÃÂ÷ÃÂúõ Python üþöõàòÃÂóûÃÂôõÃÂàÃÂðú:
#!/usr/bin/Python # -*- coding: utf-8 -*- print 'Content-Type: text/html\n' print '<H3>ÃÂÃÂûø òàÃÂÃÂþ òøôøÃÂõ, ÷ýðÃÂøàòÃÂõ ÃÂðñþÃÂðõÃÂ</H3>'
ÃÂõÃÂòÃÂü þÿõÃÂðÃÂþÃÂþü print üàÃÂþÃÂüøÃÂÃÂõü üøýøüðûÃÂýþ ýõþñàþôøüÃÂù ÷ðóþûþòþú â ñÃÂðÃÂ÷õàúûøõýÃÂð þñÃÂ÷ðÃÂõûÃÂýþ ôþûöõý ÷ýðÃÂÃÂ, úðúþò ÃÂøÿ ÿõÃÂõÃÂÃÂûðõüÃÂàõüàôðýýÃÂà(ò ýðÃÂõü ÃÂûÃÂÃÂðõ ÃÂÃÂþ ÿÃÂþÃÂÃÂþù ÃÂõúÃÂÃÂ, ÃÂþþÃÂòõÃÂÃÂÃÂòÃÂÃÂÃÂøù ÃÂþÃÂüðÃÂàHTML). ÃÂõ ÷ðñÃÂòðùÃÂõ þ ôþÿþûýøÃÂõûÃÂýþü ÿõÃÂõòþôõ ÃÂÃÂÃÂþúø \n, ýõþñàþôøüþü ôûàþÃÂôõûõýøà÷ðóþûþòúð þàÃÂõûð þÃÂòõÃÂð. ÃÂàø ôðûõõ òàüþöõÃÂõ ÿõÃÂõôðòðÃÂàûÃÂñþù HTML-úþô.
ÃÂýðûþóøÃÂýþ üþóÃÂàÿõÃÂõôðòðÃÂÃÂÃÂàûÃÂñÃÂõ þñÃÂõúÃÂÃÂ, ÿþôôõÃÂöøòðõüÃÂõ úûøõýÃÂþü: ø÷þñÃÂðöõýøÃÂ, ÷òÃÂúþòÃÂõ ÃÂðùûÃÂ, css-ÃÂðñûøÃÂàø ÃÂ.ô. ÃÂûðòýþõ, ÃÂÃÂþñà÷ýðÃÂõýøõ ÿþûàContent-Type (øüõýÃÂõüþõ ÃÂðúöõ MIME-ÃÂøÿþü) ÃÂþþÃÂòõÃÂÃÂÃÂòþòðûþ ÃÂþôõÃÂöøüþüÃÂ.
ÃÂôõÃÂàøóÃÂðÃÂÃÂ, ÷ôõÃÂàýõ øóÃÂðÃÂÃÂ...
ÃÂôýðúþ úðúþù ÃÂüÃÂÃÂû ÿþÃÂÃÂÃÂðÃÂàÃÂþÃÂüøÃÂþòðýøõ ÃÂÃÂðÃÂøÃÂõÃÂúøà, ÿþ ÃÂÃÂÃÂø, ÃÂÃÂÃÂðýøàcgi-ÃÂÃÂõýðÃÂøÃÂ, õÃÂûø ÃÂðü HTTP-ÃÂõÃÂòõàÃÂÿÃÂðòøÃÂÃÂààÃÂÃÂøü ýðüýþóþ ûÃÂÃÂÃÂõ? àþñÃÂõü-ÃÂþ ýøúðúþóþ. àð÷òõ ÃÂÃÂþ ôûàþñÃÂõóþ ÃÂð÷òøÃÂøÃÂ... àòþàò ÃÂõü CGI ÿþ-ýðÃÂÃÂþÃÂÃÂõüàÃÂøûõý, ÃÂðú ÃÂÃÂþ ò ÃÂþÃÂüøÃÂþòðýøø ôøýðüøÃÂõÃÂúøàÃÂÃÂÃÂðýøÃÂ, ÃÂþôõÃÂöøüþõ úþÃÂþÃÂÃÂà÷ðòøÃÂøàþàøýÃÂþÃÂüðÃÂøø, ÿõÃÂõôðýýþù ÿþûÃÂ÷þòðÃÂõûõü.
ÃÂÃÂþÃÂþúþû HTTP ÿÃÂõôÃÂÃÂüðÃÂÃÂøòðõàýõÃÂúþûÃÂúþ ÃÂÿþÃÂþñþò ÿõÃÂõôðÃÂø øýÃÂþÃÂüðÃÂøø þàúûøõýÃÂð ýð ÃÂõÃÂòõÃÂ, ýð÷ÃÂòðõüÃÂàüõÃÂþôðüø. ÃÂðøñþûõõ ÿþÿÃÂûÃÂÃÂýÃÂõ ø÷ ýøàâ GET, POST, PUT ø HEAD.
ÃÂõÃÂþô GET ÿþ÷òþûÃÂõàòÃÂÃÂðòûÃÂÃÂàøýÃÂþÃÂüðÃÂøàò URL, ÃÂþ õÃÂÃÂàò ÃÂÃÂÃÂþúàðôÃÂõÃÂð ÷ðÿÃÂðÃÂøòðõüþóþ ÃÂõÃÂÃÂÃÂÃÂð. ÃÂþóôð ëïýôõúÃÂû òõÃÂýõàòðü ÃÂÿøÃÂþú øÃÂúþüÃÂàÃÂÃÂÃÂðýøÃÂ, ÿþÃÂüþÃÂÃÂøÃÂõ ýð ðôÃÂõÃÂýÃÂàÃÂÃÂÃÂþúàò ñÃÂðÃÂ÷õÃÂõ â òþàÃÂðú ôðýýÃÂõ ø ÿõÃÂõôðÃÂÃÂÃÂàüõÃÂþôþü GET. ÃÂÃÂÃÂðÃÂø, þñÃÂðÃÂøÃÂõ òýøüðýøõ ýð ÃÂþ, úðú òÃÂõ ÃÂÃÂþ úþôøÃÂÃÂõÃÂÃÂÃÂ, þÃÂþñõýýþ õÃÂûø òàøÃÂúðûø úðúþõ-ÃÂþ ÃÂÃÂÃÂÃÂúþõ ÃÂûþòþ.
ÃÂÃÂûø ýð ÃÂõÃÂòõàÃÂÃÂõñÃÂõÃÂÃÂàÿõÃÂõôðÃÂàñþûÃÂÃÂøù þñÃÂõü øýÃÂþÃÂüðÃÂøø, øûø õõ öõûðÃÂõûÃÂýþ ÃÂúÃÂÃÂÃÂàþàûÃÂñþÿÃÂÃÂýÃÂàóûð÷, øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂàôÃÂÃÂóþù üõÃÂþô â POST. àôðýýþü ÃÂûÃÂÃÂðõ ò ÷ðóþûþòúõ ÿõÃÂõôðõÃÂÃÂàûøÃÂàÃÂð÷üõàÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøàôðýýÃÂà, ð ÃÂðüø ôðýýÃÂõ ÿõÃÂõÃÂÃÂûðÃÂÃÂÃÂàò ÃÂõûõ ÷ðÿÃÂþÃÂð.
ÃÂõÃÂþô PUT ÿÃÂõôýð÷ýðÃÂðõÃÂÃÂàôûàÃÂð÷üõÃÂõýøàÃÂõÃÂÃÂÃÂÃÂþò ýð ÃÂõÃÂòõÃÂõ ø ÿþ ÃÂþþñÃÂðöõýøÃÂü ñõ÷þÿðÃÂýþÃÂÃÂø ÿÃÂðúÃÂøÃÂõÃÂúø ýõ øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂÃÂ. ÃÂàø, ýðúþýõÃÂ, üõÃÂþô HEAD þÃÂõýàÿþàþö ýð GET, ÷ð ÃÂõü øÃÂúûÃÂÃÂõýøõü, ÃÂÃÂþ ÃÂõÃÂòõàò þÃÂòõàýð ÃÂðúþù ÷ðÿÃÂþàòþ÷òÃÂðÃÂðõàýõ òõÃÂàÃÂõÃÂÃÂÃÂÃÂ, ð ûøÃÂàøýÃÂþÃÂüðÃÂøàþ ýõü, ÃÂðúÃÂàúðú ôðÃÂð ÿþÃÂûõôýõóþ ø÷üõýõýøÃÂ, ÿþüõÃÂðõüÃÂàò ÷ðóþûþòúõ. ÃÂñÃÂÃÂýþ øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂàÿÃÂþúÃÂø-ÃÂõÃÂòõÃÂðüø ôûàþÿÃÂõôõûõýøàëÃÂòõöõÃÂÃÂøû øüõÃÂÃÂøàÃÂààýøàôðýýÃÂàâ ÃÂÃÂþøàûø ÷ðÿÃÂðÃÂøòðÃÂàÃÂõÃÂÃÂÃÂàÿþòÃÂþÃÂýþ øûø üþöýþ òõÃÂýÃÂÃÂàúûøõýÃÂàÃÂþ, ÃÂÃÂþ õÃÂÃÂàò úÃÂÃÂõ.
ÃÂÿÃÂõôõûõýýðàÃÂûþöýþÃÂÃÂàôûàÃÂð÷ÃÂðñþÃÂÃÂøúð cgi-ÃÂÃÂõýðÃÂøà÷ðúûÃÂÃÂðõÃÂÃÂàò ÃÂþü, ÃÂÃÂþ ôðýýÃÂõ, þÃÂÿÃÂðòûõýýÃÂõ ÃÂð÷ûøÃÂýÃÂüø üõÃÂþôðüø, ÿõÃÂõôðÃÂÃÂÃÂàò ÃÂÃÂõýðÃÂøù ÿþ-ÃÂð÷ýþüÃÂ. âðú, øýÃÂþÃÂüðÃÂøÃÂ, ÿþÃÂÃÂÃÂÿøòÃÂðààÿþüþÃÂÃÂàPOST, ÿþôðõÃÂÃÂàýð ÃÂÃÂðýôðÃÂÃÂýÃÂù òàþô ÃÂÃÂõýðÃÂøàø üþöõàñÃÂÃÂàÃÂÃÂøÃÂðýð þÃÂÃÂÃÂôð, ýðÿÃÂøüõÃÂ, àÿþüþÃÂÃÂàsys.stdin.read(size) øûø ôðöõ ÃÂÃÂýúÃÂøõù raw_input() (àþÃÂàòþ òÃÂþÃÂþü ÃÂûÃÂÃÂðõ ÃÂûþöýõõ úþýÃÂÃÂþûøÃÂþòðÃÂàþñÃÂõü ÿÃÂøýøüðõüÃÂàôðýýÃÂà). ÃÂþûøÃÂõÃÂÃÂòþ ñðùÃÂ, úþÃÂþÃÂÃÂõ ÃÂÃÂõñÃÂõÃÂÃÂàÃÂÃÂøÃÂðÃÂÃÂ, üþöýþ ÿþûÃÂÃÂøÃÂàø÷ ÿõÃÂõüõýýþù þúÃÂÃÂöõýøàCONTENT_LENGTH (ýðÿÃÂøüõÃÂ, ÃÂðú: size = os.environ['CONTENT_LENGTH']).
ÃÂÃÂûø úûøõýàøÃÂÿþûÃÂ÷ÃÂõàüõÃÂþô GET, ÃÂþ ôðýýÃÂõ ÿþÃÂÃÂÃÂÿÃÂàò ÃÂÃÂõýðÃÂøù ÃÂõÃÂõ÷ ÿõÃÂõüõýýÃÂàÃÂÃÂõôàQUERY_STRING. ÃÂõÃÂþô, úþÃÂþÃÂÃÂü ôðýýÃÂõ ÿõÃÂõôðýà(ýÃÂöýþ öõ úðú-ÃÂþ ÃÂð÷þñÃÂðÃÂÃÂÃÂÃÂ, óôõ øàøÃÂúðÃÂÃÂ) üþöýþ òÃÂõóôð ÿþûÃÂÃÂøÃÂàø÷ REQUEST_METHOD.
ÃÂÃÂÃÂàõÃÂõ þôøý þÃÂþñÃÂù ÃÂûÃÂÃÂðù. ÃÂÃÂûø ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàüõÃÂþôþü GET, ýþ àøÃÂÿþûÃÂ÷þòðýøõü ëøýôõúÃÂýþóþû ÃÂþÃÂüðÃÂð, úþÃÂþÃÂÃÂù ÃÂþÃÂüøÃÂÃÂõÃÂÃÂàÃÂõóþü <ISINDEX>, ÃÂþ ò ÃÂÃÂþü ÃÂûÃÂÃÂðõ þýø úþôøÃÂÃÂÃÂÃÂÃÂàýõ ò òøôõ ëÿõÃÂõüõýýðÃÂ=÷ýðÃÂõýøõ&ÿõÃÂõüõýýðÃÂ=÷ýðÃÂõýøõ&...û, ð úðú ë÷ýðÃÂõýøõ+÷ýðÃÂõýøõ+...û. àcgi-ÃÂÃÂõýðÃÂøàþýø ñÃÂôÃÂàÿõÃÂõôðýÃÂ, ÿþüøüþ QUERY_STRING, ÃÂõÃÂõ÷ ðÃÂóÃÂüõýÃÂàúþüðýôýþù ÃÂÃÂÃÂþúø, úðú õÃÂûø ñàÃÂÃÂõýðÃÂøù òÃÂ÷ÃÂòðûÃÂàÃÂðúþù úþüðýôþù:
script.cgi arg1 arg2 arg3
âþ õÃÂÃÂÃÂ, ýð ÃÂÃÂþàÃÂð÷ ÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøõ ôðýýÃÂõ üþöýþ ñÃÂôõàÿþûÃÂÃÂøÃÂàúðú sys.argv[1] ø ÃÂ.ô.
ÃÂðú òøôøÃÂõ, þóÃÂþüýþõ ÃÂøÃÂûþ òðÃÂøðýÃÂþò, ÿÃÂõôÃÂÃÂüþÃÂÃÂõýýÃÂàCGI-øýÃÂõÃÂÃÂõùÃÂþü, úþÃÂþÃÂÃÂõ òÃÂõ ôþûöýàñÃÂÃÂàÃÂÃÂÃÂõýàÿÃÂø ÃÂð÷ÃÂðñþÃÂúõ ÃÂÃÂõýðÃÂøÃÂ, üþöõàòÃÂ÷òðÃÂàýõÃÂòýÃÂù ÃÂøú ôðöõ àþÿÃÂÃÂýÃÂàÿÃÂþóÃÂðüüøÃÂÃÂþò, úþÃÂþÃÂÃÂõ ø òþ ÃÂýõ ÿþÃÂøàþýÃÂúàýðñøòðÃÂàÿþ ÿþôÃÂÃÂúõ úðúþù-ÃÂþ úþô. àõÃÂûø õÃÂõ òÃÂÿþüýøÃÂÃÂ, ÃÂÃÂþ ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàò ÷ðúþôøÃÂþòðýýþü òøôõ (ÃÂÃÂþ ðýóûøÃÂðýðü àþÃÂþÃÂþ â ò÷ÃÂû ÷ýðÃÂõýøõ ÿõÃÂõüõýýþù ø ÃÂðñþÃÂðù, ð ýðü-ÃÂþ àòðüø ÃÂÃÂþ ÷ýðÃÂõýøõ òõÃÂýõÃÂÃÂàò òøôõ %EC%E4%E0), ôð õÃÂõ ø þ ÿÃÂþòõÃÂúõ ÃÂÃÂøàôðýýÃÂàýÃÂöýþ ÿþ÷ðñþÃÂøÃÂÃÂÃÂÃÂ, ÃÂÃÂþñàúðúþù-ýøñÃÂôàýðÃÂøýðÃÂÃÂøù àðúõàýõ ÿþÿÃÂÃÂðûÃÂà÷ðÃÂÃÂðòøÃÂàýðàÃÂõÃÂòõàÃÂðñþÃÂðÃÂàÿþ-ÃÂòþõüÃÂ... ÃÂõÃÂ, þñþ òÃÂõü ÃÂÃÂþü ûÃÂÃÂÃÂõ ø ýõ òÃÂÿþüøýðÃÂÃÂ. ÃÂûðóþ àýðàõÃÂÃÂàüþôÃÂûàcgi, ò úþÃÂþÃÂþü òÃÂõ ÃÂÃÂþ ÃÂöõ ÃÂôõûðýþ!
ÃÂþ þ ýõü â ÃÂÃÂÃÂàÿþ÷öõ. áýðÃÂðûð ÿðÃÂàÃÂûþò ýÃÂöýþ ÃÂúð÷ðÃÂàþ HTML-ÃÂþÃÂüðà.
äþÃÂüøÃÂÃÂõü ÃÂþÃÂüÃÂ
çÃÂþñàòðü ñÃÂûþ ÿÃÂþÃÂõ ÿþýÃÂÃÂàÃÂðÃÂÃÂüðÃÂÃÂøòðõüÃÂù ÃÂõóþôýàÿÃÂøüõÃÂ, úþÃÂþÃÂúþ ÃÂúðöàÿÃÂþ ÃÂþ, úðú öõ úûøõýàòÃÂÿþûýÃÂõàÿõÃÂõôðÃÂàôðýýÃÂàýðÃÂõüàcgi-ÃÂÃÂõýðÃÂøÃÂ. ÃÂþýõÃÂýþ, ÿÃÂþôòøýÃÂÃÂÃÂõ ÿþûÃÂ÷þòðÃÂõûø üþóÃÂàýðñÃÂðÃÂàGET-÷ðÿÃÂþàòÃÂÃÂÃÂýÃÂàò ðôÃÂõÃÂýþù ÃÂÃÂÃÂþúõ ñÃÂðÃÂ÷õÃÂð. Ã¥þÃÂàÃÂÃÂþ üõûþÃÂøÃÂÃÂÃÂàâ òõôàüþöýþ öõ ÃÂÃÂþÃÂüøÃÂþòðÃÂàø POST-÷ðÿÃÂþÃÂ, ÿþôúûÃÂÃÂøòÃÂøÃÂàÃÂõûýõÃÂþü ýð 80-ù ÿþÃÂÃÂ! ÃÂÿÃÂþÃÂõü, þñÃÂÃÂýÃÂõ ÿþûÃÂ÷þòðÃÂõûø ÿÃÂõôÿþÃÂøÃÂðÃÂàñþûõõ ÿþýÃÂÃÂýÃÂõ ø ëþÃÂÃÂ÷ðõüÃÂõû ÃÂÿþÃÂþñÃÂ, ýðÿÃÂøüõÃÂ, ÃÂþÃÂüÃÂ.
ÃÂðú þýø òÃÂóûÃÂôÃÂÃÂ, ôÃÂüðÃÂ, úðöôÃÂù ÷ýðõÃÂ. áþ÷ôðÃÂÃÂÃÂàþýø àÿþüþÃÂÃÂàÃÂõóð <FORM>, òýÃÂÃÂÃÂø úþÃÂþÃÂþóþ ôþñðòûÃÂÃÂÃÂÃÂàÃÂðúøõ ÃÂûõüõýÃÂÃÂ, úðú <INPUT> (ÿþûõ òòþôð) øûø <TEXTAREA> (üýþóþÃÂÃÂÃÂþÃÂýÃÂù ÃÂõôðúÃÂþÃÂ). ÃÂÃÂøü ÃÂûõüõýÃÂðü, õÃÂûø øàôðýýÃÂõ ôþûöýàñÃÂÃÂàÿõÃÂõôðýàýð ÃÂõÃÂòõÃÂ, ÿÃÂøÃÂòðøòðÃÂÃÂÃÂàøüõýð àÿþüþÃÂÃÂàðÃÂÃÂøñÃÂÃÂð name. ÃÂðÃÂðûÃÂýþõ ÷ýðÃÂõýøõ ÷ðôðõÃÂÃÂàÿðÃÂðüõÃÂÃÂþü value ø ò ôðûÃÂýõùÃÂõü ôûàëÃÂõôðúÃÂøÃÂÃÂõüÃÂàû ÿþûõù üþöõàñÃÂÃÂàø÷üõýõýþ ÿþûÃÂ÷þòðÃÂõûõü. ÃÂþóôð ÿþûÃÂ÷þòðÃÂõûàýðöøüðõàúýþÿúàëÃÂÃÂÿÃÂðòøÃÂÃÂû (ýðôÿøÃÂàýð ýõù, ò ÿÃÂøýÃÂøÿõ, üþöýþ ø÷üõýøÃÂÃÂ), ÃÂþ ñÃÂðÃÂ÷õàþñÃÂõôøýÃÂõàòÃÂõ ôðýýÃÂõ ÿþûõù ò ÿðÃÂàname=value, ÃÂð÷ôõûÃÂàøàÃÂøüòþûþü &. ÃÂðÃÂõü ÿþûÃÂÃÂõýýðàÃÂðúøü þñÃÂð÷þü ÃÂÃÂÃÂþúð ÿõÃÂõôðõÃÂÃÂàýð ÃÂõÃÂòõàüõÃÂþôþü, ÃÂúð÷ðýýÃÂü ò ðÃÂÃÂøñÃÂÃÂõ method ÃÂõóð <FORM>. ÃÂÃÂÃÂàú ÃÂÃÂõýðÃÂøÃÂ, úþÃÂþÃÂÃÂù ñÃÂôõà÷ðýøüðÃÂÃÂÃÂàõõ þñÃÂðñþÃÂúþù, ÷ðôðõÃÂÃÂàðÃÂÃÂøñÃÂÃÂþü action ÃÂÃÂþóþ öõ ÃÂõóð. ÃÂÃÂûø action ýõ ÷ðôðý, ÃÂþ ôðýýÃÂõ ÿõÃÂõôðÃÂÃÂÃÂàÃÂðùûÃÂ, ÃÂÃÂþÃÂüøÃÂþòðòÃÂõüàÃÂõúÃÂÃÂÃÂàÃÂÃÂÃÂðýøÃÂúÃÂ.
ÃÂÃÂûø ÃÂÃÂþ-ÃÂþ ýõ ÃÂþòÃÂõü ÿþýÃÂÃÂýþ, þñÃÂðÃÂøÃÂõÃÂàú úþôàÃÂð÷ÃÂðñðÃÂÃÂòðõüþù óþÃÂÃÂõòþù úýøóø, úþÃÂþÃÂÃÂù ÿÃÂøòõôõý ýøöõ.
ÃÂðàÃÂÿðÃÂøÃÂõûàâ üþôÃÂûàcgi
ÃÂþ÷òÃÂðÃÂðõüÃÂàú þñÃÂðñþÃÂúõ òÃÂõóþ ÃÂÃÂþóþ ôþñÃÂð, úþÃÂþÃÂþõ ÃÂþÃÂýø ÿþûÃÂ÷þòðÃÂõûõù ÃÂöõ óþÃÂþòàþñÃÂÃÂÃÂøÃÂàýð ýðàñõôýÃÂù ÃÂÃÂõýðÃÂøù. ÃÂàÃÂõÃÂøûø òþÃÂÿþûÃÂ÷þòðÃÂÃÂÃÂàÃÂÃÂðýôðÃÂÃÂýÃÂüø ÃÂÃÂõôÃÂÃÂòðüø Python, ø ÷ôõÃÂàòÃÂõ ôõùÃÂÃÂòøÃÂõûÃÂýþ þÃÂõýàÿÃÂþÃÂÃÂþ â øüÿþÃÂÃÂøÃÂÃÂùÃÂõ üþôÃÂûàcgi ø, ÃÂþ÷ôðò þñÃÂõúàúûðÃÂÃÂð FieldStorage, òàÿþûÃÂÃÂøÃÂõ ÃÂõÃÂõ÷ ýõóþ ôþÃÂÃÂÃÂÿ úþ òÃÂõü ôðýýÃÂü, ÿõÃÂõôðýýÃÂü ÿþûÃÂ÷þòðÃÂõûõü, ýõ÷ðòøÃÂøüþ þàøÃÂÿþûÃÂ÷ÃÂõüþóþ üõÃÂþôð:
import cgi data = cgi.FieldStorage() for entry in data.keys(): print 'ÃÂõÃÂõüõýýðà%s øüõõà÷ýðÃÂõýøõ %s' % (entry, data[entry].value)
ÃÂÃÂûø òðü ýÃÂöýþ ÿþûÃÂÃÂøÃÂà÷ýðÃÂõýøõ þÿÃÂõôõûõýýþóþ ÿþûÃÂ, ÃÂÃÂþ ôõûðõÃÂÃÂàÃÂðú:
field = data['field'].value
ÃÂþüøüþ ÿþûÃÂ÷þòðÃÂõûÃÂÃÂúøàôðýýÃÂà, þñÃÂõúàúûðÃÂÃÂð FieldStorage ÃÂþôõÃÂöøàøýÃÂþÃÂüðÃÂøàø þ ÿþûÃÂà÷ðóþûþòúð (ò ýðÃÂõü ÿÃÂøüõÃÂõ øàüþöýþ ÿþûÃÂÃÂøÃÂàø÷ ÃÂûþòðÃÂàdata.headers). MIME-ÃÂøÿ ôðýýÃÂà(ÿõÃÂõôðòðõüÃÂù ÿþûõü ÷ðóþûþòúð Content-Type) üþöýþ ÿþûÃÂÃÂøÃÂàø÷ ðÃÂÃÂøñÃÂÃÂð data.type. çõÃÂõ÷ ÃÂÃÂþàöõ þñÃÂõúàüþöõàñÃÂÃÂàòÃÂÿþûýõýð ø ÷ðóÃÂÃÂ÷úð ÃÂðùûð.
á ÿþüþÃÂÃÂàüõÃÂþôþò keys() ø has_key() üþöýþ òÃÂÿþûýÃÂÃÂàþñÃÂðñþÃÂúàÿþûÃÂÃÂõýýÃÂàôðýýÃÂàò ÃÂøúûõ ø ÿÃÂþòõÃÂÃÂÃÂàýðûøÃÂøõ ÃÂþù øûø øýþù ÿõÃÂõüõýýþù. ÃÂÃÂÃÂðÃÂø óþòþÃÂÃÂ, ÿÃÂþòõÃÂÃÂÃÂàýðûøÃÂøõ ÿõÃÂõüõýýþù òþ òàþôýÃÂàôðýýÃÂà, ÿÃÂõöôõ ÃÂõü ÿÃÂøÃÂÃÂÃÂÿðÃÂàú øàþñÃÂðñþÃÂúõ, ýÃÂöýþ ýõÿÃÂõüõýýþ â òõôà÷ðÿÃÂþàÃÂþÃÂüøÃÂÃÂõÃÂÃÂàúûøõýÃÂþü, ð úÃÂþ ÷ýðõÃÂ, ÃÂÃÂþ àýõóþ ýð ÃÂüõ?
ÃÂð÷øÃÂÃÂõü ôðýýÃÂõ
ÃÂÃÂðú, ÿþûÃÂÃÂðÃÂàôðýýÃÂõ þàúûøõýÃÂð üàýðÃÂÃÂøûøÃÂÃÂ. ÃÂÃÂÿÃÂðòûÃÂÃÂàÃÂþöõ ÃÂüõõü. ÃÂÃÂÃÂðûþÃÂàÿÃÂøôÃÂüðÃÂÃÂ, úðú ÃÂÃÂø ôðýýÃÂõ ûÃÂÃÂÃÂõ òÃÂõóþ àÃÂðýøÃÂÃÂ. ÃÂþýõÃÂýþ, ôûàýõÃÂûþöýþù óþÃÂÃÂõòþù úýøóø àýõñþûÃÂÃÂþù ýðóÃÂÃÂ÷úþù òÿþûýõ àòðÃÂøûþ ñàø ÃÂõúÃÂÃÂþòÃÂàÃÂðùûþò. ÃÂÃÂðòôð, ÃÂðü õÃÂÃÂàÃÂòþø ÃÂûþöýþÃÂÃÂø â õÃÂûø ÃÂÃÂð÷àÿÃÂÃÂàÃÂõûþòõú ÷ðàþÃÂÃÂàòÃÂÃÂúð÷ðÃÂàÃÂòþõ üýõýøõ þ òðÃÂõù úÃÂÃÂÃÂõùÃÂõù ôþüðÃÂýõù ÃÂÃÂÃÂðýøÃÂúõ, ÃÂþ ÃÂÃÂõýðÃÂøàÿÃÂøôõÃÂÃÂàúðúøü-ÃÂþ þñÃÂð÷þü ÃÂõóÃÂûøÃÂþòðÃÂàôþÃÂÃÂÃÂÿ ú ÃÂðùûÃÂ-àÃÂðýøûøÃÂà(úðú üøýøüÃÂü, þñÃÂðñðÃÂÃÂòðÃÂàÃÂøÃÂÃÂðÃÂøÃÂ, õÃÂûø ÃÂðùû ÃÂöõ þÃÂúÃÂÃÂàýð ÷ðÿøÃÂàôÃÂÃÂóøü ÃÂú÷õüÿûÃÂÃÂþü ÃÂÃÂõýðÃÂøÃÂ). ÃÂþ ÷ðÃÂõü ýðü òÃÂõ ÃÂÃÂø óþûþòýÃÂõ ñþûø? ÃÂÃÂûø üàÃÂðú ûþòúþ þÃÂòõÃÂÃÂõûøÃÂàþàýõþñàþôøüþÃÂÃÂø òÃÂÃÂÃÂýÃÂàÃÂð÷ñøÃÂðÃÂàHTTP-÷ðÿÃÂþÃÂÃÂ, ÃÂþ ýõÃÂöõûø ýõ ýðùôõü ÃÂÃÂþ-ÃÂþ ÿþôàþôÃÂÃÂõõ ýð ÃÂÃÂþàÃÂð÷?
ÃÂþýõÃÂýþ, ýðùôõü! àÃÂÃÂþ ëÃÂÃÂþ-ÃÂþû ýð÷ÃÂòðõÃÂÃÂàÃÂøÃÂÃÂõüþù ÃÂÿÃÂðòûõýøàñð÷ðüø ôðýýÃÂà(ò ÿÃÂþÃÂÃÂþÃÂõÃÂÃÂõ â áãÃÂÃÂ). âõÿõÃÂàýðÃÂõ ôõûþ â þÃÂÿÃÂðòøÃÂà÷ðÿÃÂþàø ÿþûÃÂÃÂøÃÂàþÃÂòõÃÂ. ÃÂÃÂõ þÃÂÃÂðûÃÂýþõ â ÃÂöõ ýõ ýðÃÂð ÷ðñþÃÂð.
ÃÂûàÃÂÃÂþóþ ÿÃÂøüõÃÂð àòÃÂñÃÂðû ò úðÃÂõÃÂÃÂòõ ëþÃÂòõÃÂÃÂÃÂòõýýþóþû ÷ð àÃÂðýõýøõ ôðýýÃÂàÃÂõÃÂòõàñð÷ ôðýýÃÂàPostgreSQL. ÃÂþÃÂúþûÃÂúàüàÿøÃÂõü ýàþÃÂõýàÿÃÂþÃÂÃÂÃÂàóþÃÂÃÂõòÃÂàúýøóÃÂ, ÃÂþ ø ÃÂÃÂÃÂÃÂúÃÂÃÂÃÂð ñð÷àñÃÂôõààýðàÃÂûõüõýÃÂðÃÂýþù â þôýð ÃÂðñûøÃÂð àÃÂÃÂõüàÿþûÃÂüø: òÃÂõüàÿÃÂñûøúðÃÂøø ÃÂþþñÃÂõýøÃÂ, øüàðòÃÂþÃÂð ø, ÃÂþñÃÂÃÂòõýýþ, ÃÂðüþ ÃÂþþñÃÂõýøõ:
admin@toshiba:~$ psql Welcome to psql 8.1.4, the PostgreSQL interactive terminal. guestbook=# create user "www-data" nocreatedb nocreateuser; CREATE ROLE admin=# create database guestbook with owner "www-data"; CREATE DATABASE admin=# \connect guestbook ÃÂàÿþôÃÂþõôøýøûøÃÂàú ñð÷õ ôðýýÃÂà"guestbook". guestbook=# create table guestbook ( guestbook(# datum timestamp, author varchar, message varchar); CREATE TABLE guestbook=# alter table guestbook owner to "www-data"; ALTER TABLE guestbook=# \q admin@toshiba:~$
ÃÂþöðûÃÂù, õôøýÃÂÃÂòõýýþõ, ÃÂÃÂþ ÷ôõÃÂàýÃÂöýþ ÿþÃÂÃÂýøÃÂÃÂ, ÃÂÃÂþ ÿþÃÂõüàñð÷õ ø ÃÂðñûøÃÂõ üàýð÷ýðÃÂøûø òûðôõûÃÂÃÂõü ÿþûÃÂ÷þòðÃÂõûàwww-data. ÃÂÃÂþÃÂÃÂþ ú ýøü ñÃÂôõàþñÃÂðÃÂðÃÂÃÂÃÂàcgi-ÃÂÃÂõýðÃÂøù, ÃÂðñþÃÂðÃÂÃÂøù àÿÃÂðòðüø HTTP-ÃÂõÃÂòõÃÂð Apache, úþÃÂþÃÂÃÂù, ò ÃÂòþàþÃÂõÃÂõôÃÂ, øÃÂÿþûýÃÂõÃÂÃÂàþàøüõýø ôðýýþóþ ÿþûÃÂ÷þòðÃÂõûà[ò òðÃÂõü ôøÃÂÃÂÃÂøñÃÂÃÂøòõ þý üþöõàýð÷òðÃÂÃÂÃÂàÿþ-ôÃÂÃÂóþüÃÂ, â ÿÃÂøü. ÃÂõô.]. àPostgreSQL ÿþ ÃÂüþûÃÂðýøàÃÂÃÂõñÃÂõÃÂ, ÃÂÃÂþñàøüàÿþûÃÂ÷þòðÃÂõûàò ÃÂàÃÂþòÿðôðûþ àõóþ ÃÂøÃÂÃÂõüýÃÂü øüõýõü. ÃÂýõ ÃÂÃÂþ úðöõÃÂÃÂàôþÃÂÃÂðÃÂþÃÂýþ ÃÂôþñýÃÂü, àþÃÂàòÃÂ, úþýõÃÂýþ, üþöõÃÂõ ÿþÃÂÃÂÃÂÿøÃÂàÿþ-ÃÂòþõüÃÂ.
DB API ýð ÃÂÃÂÃÂðöõ ÃÂýøÃÂøúðÃÂøø
ÃÂÃÂÃÂðûþÃÂàÃÂð÷þñÃÂðÃÂÃÂÃÂÃÂ, úðú öõ Python ò÷ðøüþôõùÃÂÃÂòÃÂõààñð÷ðüø ôðýýÃÂà. ÃÂûàÃÂÃÂþóþ Python ÿÃÂõôþÃÂÃÂðòûÃÂõàDB API â ÃÂÿõÃÂøðûÃÂýÃÂù øýÃÂõÃÂÃÂõùÃÂ, ÃÂýøÃÂøÃÂøÃÂÃÂÃÂÃÂøù ýðñþàüõÃÂþôþò, úþÃÂþÃÂÃÂõ ñÃÂôÃÂàþôøýðúþòþ ÃÂðñþÃÂðÃÂàýõ÷ðòøÃÂøüþ þàÃÂþóþ, àúðúþù áãÃÂàüàò÷ðøüþôõùÃÂÃÂòÃÂõü. ÃÂûàÃÂðñþÃÂààPostgreSQL ýðü ÿþýðôþñøÃÂÃÂàüþôÃÂûàPyPgSQL (ò ÃÂÃÂðýôðÃÂÃÂýþù ÿþÃÂÃÂðòúõ õóþ üþöõàýõ þúð÷ðÃÂÃÂÃÂÃÂ, ýþ òðàüõýõôöõàÿðúõÃÂþò ýðòõÃÂýÃÂúð ñÃÂôõàò úÃÂÃÂÃÂõ, úðú õóþ ÃÂÃÂÃÂðýþòøÃÂÃÂ; úÃÂÃÂðÃÂø, ÃÂÃÂþ ýõ õôøýÃÂÃÂòõýýÃÂù üþôÃÂûàâ àòðÃÂ, òþ÷üþöýþ, ñÃÂôõàPyGreSQL, úþÃÂþÃÂÃÂù ÃÂðñþÃÂðõàýøÃÂÃÂÃÂàýø àÃÂöõ ø àÃÂõüø öõ ÃÂðüÃÂüø üõÃÂþôðüø).
DB API þÿÃÂõôõûÃÂõàÃÂÃÂðýôðÃÂÃÂýÃÂõ üõÃÂþôàÃÂðñþÃÂààñð÷ðüø ôðýýÃÂà, ÃÂðú ÃÂÃÂþ, úðúþù ñàüþôÃÂûàòàýø ÷ðóÃÂÃÂ÷øûø ø àúðúþù ñàáãÃÂàýø ÃÂðñþÃÂðûø (ñÃÂôàÃÂþ MySQL, PostgreSQL, SQLite øûø ÃÂÃÂþ-ÃÂþ õÃÂõ), üõýÃÂÃÂÃÂÃÂàñÃÂôõàÃÂþûÃÂúþ øüàüþôÃÂûÃÂ. ÃÂûðòýþõ, ÃÂÃÂþñàøÃÂÿþûÃÂ÷ÃÂõüÃÂù üþôÃÂûàÃÂþþÃÂòõÃÂÃÂÃÂòþòðû DB API. àðÃÂÃÂüþÃÂÃÂøü úþÃÂþÃÂúþ þÃÂýþòýÃÂõ üõÃÂþôÃÂ:
conn = connect(dsn='localhost', user='admin', password='superparol', database='mydb')
âðú þÃÂÃÂÃÂõÃÂÃÂòûÃÂõÃÂÃÂàÿþôúûÃÂÃÂõýøõ ú ñð÷õ. à÷ðòøÃÂøüþÃÂÃÂø þàÃÂøÃÂÃÂðÃÂøø, òðü üþöõàÿþÃÂÃÂõñþòðÃÂÃÂÃÂàÃÂúð÷ðÃÂàÃÂþûÃÂúþ ýÃÂöýÃÂõ ÿðÃÂðüõÃÂÃÂà(ýðÿÃÂøüõÃÂ, øüààþÃÂÃÂð 'localhost' ÿþôÃÂð÷ÃÂüõòðõÃÂÃÂàÿþ ÃÂüþûÃÂðýøÃÂ).
cur = conn.cursor()
ÃÂÃÂÃÂÃÂþÃÂàÿþôôõÃÂöøòðÃÂÃÂÃÂàôðûõúþ ýõ òÃÂõüø áãÃÂÃÂ, ýþ ôûàþñÃÂýþÃÂÃÂø ò DB API þýø òòõôõýàø, ò ÃÂûÃÂÃÂðõ ýõþñàþôøüþÃÂÃÂø, ôþûöýàÃÂüÃÂûøÃÂþòðÃÂÃÂÃÂàüþôÃÂûÃÂüø ÃÂþÿÃÂÃÂöõýøàøÃÂúÃÂÃÂÃÂÃÂòõýýþ. âðú ÃÂÃÂþ ýõ ÷ðñÃÂòðùÃÂõ þÃÂÿÃÂðòûÃÂÃÂàòÃÂõ òðÃÂø ÷ðÿÃÂþÃÂàÃÂõÃÂõ÷ úÃÂÃÂÃÂþÃÂ.
cur.execute('''SELECT * FROM mytable''')
âðú òÃÂÿþûýÃÂõÃÂÃÂàSQL-÷ðÿÃÂþÃÂ. ÃÂÃÂûø ò ÃÂÃÂÃÂþúõ ÷ðÿÃÂþÃÂð øÃÂÿþûÃÂ÷ÃÂÃÂÃÂÃÂà÷ýðúþüõÃÂÃÂð %s, ÃÂþ òÃÂþÃÂÃÂü ÿðÃÂðüõÃÂÃÂþü ÿõÃÂõôðõÃÂÃÂàÃÂÿøÃÂþú ÿõÃÂõüõýýÃÂà-÷ýðÃÂõýøù, ÿÃÂøÃÂõü ò SQL-÷ðÿÃÂþÃÂõ ÷ýðúþüõÃÂÃÂð ýõ ÃÂÃÂõñÃÂõÃÂÃÂàþúÃÂÃÂöðÃÂàðÿþÃÂÃÂÃÂþÃÂðüø â üþôÃÂûàÃÂôõûðõàÃÂÃÂþ ÃÂðüþÃÂÃÂþÃÂÃÂõûÃÂýþ ò ÷ðòøÃÂøüþÃÂÃÂø þàÃÂøÿð ÿõÃÂõüõýýþù.
cur.fetchall()
ÃÂþ÷òÃÂðÃÂðõàôòÃÂüõÃÂýÃÂù ÃÂÿøÃÂþú (ÃÂÃÂÃÂþúø â ÿþûÃÂ) ÿþûÃÂÃÂõýýÃÂàþàáãÃÂàôðýýÃÂà. áÃÂÃÂõÃÂÃÂòÃÂÃÂàø ôÃÂÃÂóøõ üõÃÂþôÃÂ, þ÷ýðúþüøÃÂÃÂÃÂààúþÃÂþÃÂÃÂüø òàÃÂüþöõÃÂõ ò ôþúÃÂüõýÃÂðÃÂøø øûø àÿþüþÃÂÃÂà÷ýðúþüþù òðü ÃÂÃÂýúÃÂøø dir() ôð ÿðÃÂÃÂ-ÃÂÃÂþùúø ýõÃÂûþöýÃÂàÃÂúÃÂÿõÃÂøüõýÃÂþò.
ÃÂðúÃÂõÿûÃÂõü ýð ÿÃÂðúÃÂøúõ
ÃÂõÃÂõùôõü ú ÃÂðÃÂÃÂüþÃÂÃÂõýøàýðÃÂõóþ ÿÃÂøüõÃÂð. ÃÂðÃÂýõü ÃÂÃÂðýôðÃÂÃÂýþ â ÃÂúðöõü úþôøÃÂþòúÃÂ, ÿþôúûÃÂÃÂøü ýÃÂöýÃÂõ üþôÃÂûø:
#!/usr/bin/Python # -*- coding: utf-8 -*- import PyPgSQL.PgSQL as pg import cgi
ÃÂðûõõ, þÿÃÂõôõûøü ôòõ ÃÂÃÂýúÃÂøø. ÃÂõÃÂòðàñÃÂôõàþÃÂòõÃÂðÃÂà÷ð ôþñðòûõýøõ ýþòþóþ ÃÂþþñÃÂõýøàò ñð÷ÃÂ:
def addMessage(author, message): db = pg.connect(database="guestbook") c = db.cursor() c.execute("""INSERT INTO guestbook (datum, author, message) VALUES ('now', %s, %s);""", (author, message)) c.close() db.commit() db.close() print "Content-Type: text/html" print "Location: ?#form\n"
ÃÂðú òøôøÃÂõ, òÃÂõ þÃÂõýàôðöõ ûþóøÃÂýþ: ÃÂÃÂÃÂðýðòûøòðõü ÃÂþõôøýõýøõ àÃÂà(ÿþÃÂúþûÃÂúàò ýðÃÂõü ÃÂûÃÂÃÂðõ ÿþôúûÃÂÃÂõýøõ òÃÂÿþûýÃÂõÃÂÃÂààøüõýõü ÃÂõúÃÂÃÂõóþ ÃÂøÃÂÃÂõüýþóþ ÿþûÃÂ÷þòðÃÂõûÃÂ, ÃÂþ ôþÃÂÃÂðÃÂþÃÂýþ ÃÂúð÷ðÃÂàÃÂþûÃÂúþ øüàñð÷ÃÂ), ÃÂþ÷ôðõü úÃÂÃÂÃÂþà(ò PostgreSQL þýø ýõ ÿÃÂøüõýÃÂÃÂÃÂÃÂÃÂ, ýþ þýø ÃÂüÃÂûøÃÂÃÂÃÂÃÂÃÂàúðöôÃÂü üþôÃÂûõü, ÿÃÂõÃÂõýôÃÂÃÂÃÂøü ýð ÃÂþþÃÂòõÃÂÃÂÃÂòøõ DB API), òÃÂÿþûýÃÂõÃÂÃÂà÷ðÿÃÂþÃÂ, ÷ðúÃÂÃÂòðõÃÂÃÂàúÃÂÃÂÃÂþÃÂ, ÃÂøúÃÂøÃÂÃÂÃÂÃÂÃÂàø÷üõýõýøà(PostgreSQL øÃÂÿþûÃÂ÷ÃÂõàÃÂÃÂðý÷ðúÃÂøø, ÿþÃÂÃÂþüàòÃÂÿþûýõýøõ üõÃÂþôð commit() þñÃÂ÷ðÃÂõûÃÂýþ, øýðÃÂõ òðÃÂø ø÷üõýõýøàýõ ñÃÂôÃÂàÃÂþàÃÂðýõýÃÂ), ø, ýðúþýõÃÂ, ÷ðúÃÂÃÂòðõü ÃÂðüþ ÃÂþõôøýõýøõ àñð÷þù. àÿþûõ datum ÷ðýþÃÂøü ÷ýðÃÂõýøõ òÃÂÃÂÃÂþõýýþù ÿõÃÂõüõýýþù PostgreSQL â now, úþÃÂþÃÂðàúðöôÃÂù ÃÂð÷ ÷ðüõýÃÂõÃÂÃÂàÃÂõúÃÂÃÂøü ÷ýðÃÂõýøõü ôðÃÂàø òÃÂõüõýø.
ÃÂàø ÿõÃÂðÃÂà÷ðóþûþòúð ëLocationû òÃÂÿþûýÃÂõÃÂÃÂàôûàÃÂþóþ, ÃÂÃÂþñàÿõÃÂõýðÿÃÂðòøÃÂàÿþûÃÂ÷þòðÃÂõûàýð ÃÂÃÂþàöõ ÃÂÃÂõýðÃÂøù, ýþ ÃÂöõ ñõ÷ ÿðÃÂðüõÃÂÃÂþò â üàöõ ôþûöýàÿþúð÷ðÃÂàúûøõýÃÂÃÂ, ÃÂÃÂþ þý ýð ÃÂðüþü ôõûõ òòõû? (ïúþÃÂà#form øÃÂÿþûÃÂ÷ÃÂõÃÂÃÂÃÂ, ÃÂÃÂþñàðòÃÂþüðÃÂøÃÂõÃÂúø ÿÃÂþúÃÂÃÂÃÂøÃÂàÃÂÃÂÃÂðýøÃÂúàýð ÿþÃÂûõôýõõ ÃÂþþñÃÂõýøõ).
ÃÂÃÂþÃÂðàÃÂÃÂýúÃÂøàñÃÂôõàþÃÂòõÃÂðÃÂà÷ð òÃÂòþô ýð ÃÂúÃÂðý ÃÂöõ þÃÂÃÂðòûõýýÃÂàò úýøóõ ÷ðÿøÃÂõù, ð ÃÂðúöõ ÷ð ÃÂþÃÂüÃÂ, àÿþüþÃÂÃÂàúþÃÂþÃÂþù üþöýþ ñÃÂôõàôþñðòøÃÂàø ÃÂòþõ òÃÂÃÂúð÷ÃÂòðýøõ:
def showGB(): db = pg.connect(database="guestbook") c = db.cursor() c.execute("""SELECT datum, author, message FROM guestbook ORDER BY datum;""") res = c.fetchall() c.close() db.close()
àÃÂÃÂþü ÃÂÃÂðóüõýÃÂõ üàòÃÂñøÃÂðõü òÃÂõ ÃÂÃÂÃÂþúø ø÷ ýðÃÂõù ÃÂðñûøÃÂàôðýýÃÂà, ÃÂþÃÂÃÂøÃÂÃÂàøàÿþ ôðÃÂõ. àõ÷ÃÂûÃÂÃÂðàÃÂþàÃÂðýÃÂõÃÂÃÂàò ÿõÃÂõüõýýþù res, àúþÃÂþÃÂþù ø ñÃÂôõü ÃÂðñþÃÂðÃÂÃÂ. âõÿõÃÂàþÃÂÃÂðûþÃÂàûøÃÂàðúúÃÂÃÂðÃÂýõýÃÂúþ ÃÂð÷ûþöøÃÂàýðÃÂø ôðýýÃÂõ ÿþ ÃÂðñûøÃÂúðü ø òÃÂòõÃÂÃÂø øàýð ÃÂúÃÂðý:
print "Content-Type: text/html\n" print "<H1 style='color:#7777FF'><U>ÃÂõûÃÂúðü ú ýðü ò óþÃÂÃÂø!</U></H1>" for item in res: print """<TABLE width='90%%'> <TR><TD><SMALL>âþòðÃÂøà<B>%s</B> ÿþòõôðûýðü ÃÂûõôÃÂÃÂÃÂõõ:</SMALL> <TD align='right'><SMALL>%s</SMALL> <TR><TD style='background-color:#DDDDFF' colspan='2'>%s </TABLE>""" % (item[1], str(item[0])[:19], item[2]) print "<HR><A name='form'><H3>ÃÂÃÂøÃÂþõôøýÃÂùÃÂõÃÂàú ôøÃÂúÃÂÃÂÃÂøø:</H3>" print """<FORM method='GET'> ÃÂðÃÂõ øüÃÂ: <INPUT type='text' name='author'><BR> çÃÂþ òàôÃÂüðõÃÂõ ÿþ ÃÂÃÂþüàÿþòþôÃÂ:<BR> <TEXTAREA name='message' rows='5' cols='80'></TEXTAREA><BR> <INPUT type='submit' value='ÃÂÃÂÿÃÂðòøÃÂÃÂ'> </FORM>"""
áüÃÂÃÂû úþýÃÂÃÂÃÂÃÂúÃÂøø str(item[0])[:19] ÷ðúûÃÂÃÂðõÃÂÃÂàò ÃÂþü, ÃÂÃÂþñàò ÃÂÃÂÃÂþúõ òÃÂõüõýø þÃÂÃÂõÃÂàýõýÃÂöýÃÂõ ýðü üøûûøÃÂõúÃÂýôÃÂ, úþÃÂþÃÂÃÂõ ÃÂþàÃÂðýÃÂÃÂÃÂÃÂàò ÿþûõ ÃÂøÿð timestamp. ÃÂþÃÂûõ òÃÂõàþÿÃÂñûøúþòðýýÃÂàÃÂþþñÃÂõýøù òÃÂòþôøü ÃÂþÃÂüàôþñðòûõýøàýþòþóþ, ÃÂÃÂþñàúðöôÃÂù üþó ÿÃÂøÃÂþõôøýøÃÂÃÂÃÂàú ýðÃÂõù ôøÃÂúÃÂÃÂÃÂøø. ÃÂÃÂÃÂðÃÂø, ò ÃÂõóõ <FORM> üàýõ ÃÂúð÷ðûø ÿðÃÂðüõÃÂàaction, ÿþÃÂúþûÃÂúàôðýýÃÂõ ñÃÂôÃÂàÿõÃÂõôðòðÃÂÃÂÃÂàýð þñÃÂðñþÃÂúàÃÂÃÂþüàöõ ÃÂÃÂõýðÃÂøà(ñûðóþôðÃÂàÃÂõüàøüàÃÂÃÂõýðÃÂøàüþöýþ ÿÃÂøÃÂòþøÃÂàûÃÂñþõ). ÃÂðúþýõÃÂ, ÿþÃÂûõôýøù ÃÂÃÂðóüõýÃÂ:
form = cgi.FieldStorage() if form.has_key("message") and form.has_key("author"): author = cgi.escape(form["author"].value) message = cgi.escape(form["message"].value) message = message.replace("\n", "<BR>") addMessage(author, message) else: showGB()
áþ÷ôðõü FieldStorage-þñÃÂõúÃÂ, ø õÃÂûø ò ýõü õÃÂÃÂà÷ðÿþûýõýýÃÂõ ÿþûàmessage ø author (ÃÂþ õÃÂÃÂà÷ðÿÃÂþàñÃÂû ÃÂÃÂþÃÂüøÃÂþòðý ø÷ ÷ðÿþûýõýýþù ÿþûÃÂ÷þòðÃÂõûõü ÃÂþÃÂüÃÂ), ÃÂþ, ýõüýþöúþ øàþñÃÂðñþÃÂðò (ÃÂÃÂýúÃÂøàcgi.escape() ÷ðüõýÃÂõàòÃÂõ ëýõñûðóþýðôõöýÃÂõû ÃÂøüòþûàâ ýðÿÃÂøüõÃÂ, < â øàÃÂÃÂðýôðÃÂÃÂýÃÂüø SGML-ÃÂÃÂÃÂýþÃÂÃÂÃÂüø, ò ôðýýþü ÃÂûÃÂÃÂðõ â <), ÿõÃÂõôðõü ÃÂÃÂýúÃÂøø addMessage(). ÃÂñÃÂðñþÃÂúð ýÃÂöýð ôûàÃÂþóþ, ÃÂÃÂþñà÷ûþÃÂüÃÂÃÂûõýýøú ýõ üþó òòõÃÂÃÂø ò ÿþûõ ÃÂþþñÃÂõýøàøûø øüõýø ðòÃÂþÃÂð ÃÂÃÂþ-ýøñÃÂôàÃÂðúþõ:
<SCRIPT>alert('ÃÂð ÿþÃÂûø òàòÃÂõ!');</SCRIPT>
àÃÂûþòÃÂ, ÿÃÂõýõñÃÂõóðÃÂàÿÃÂþòõÃÂúþù òòõôõýýÃÂàôðýýÃÂàýø ò úþõü ÃÂûÃÂÃÂðõ ýõûÃÂ÷ÃÂ. ÃÂðùôøÃÂõ úðú-ýøñÃÂôàýð securitylab.ru ø ÿþÃÂüþÃÂÃÂøÃÂõ, ÃÂúþûÃÂúþ ÃÂÃÂ÷òøüþÃÂÃÂõù ÃÂøÿð ëXSSû þñýðÃÂÃÂöøòðõÃÂÃÂàúðöôÃÂù üõÃÂÃÂÃÂ! âðú ÃÂÃÂþ ÃÂÃÂÃÂúø ÃÂÃÂÃÂúðüø, ýþ ÿþÃÂûõôÃÂÃÂòøàüþóÃÂàñÃÂÃÂàþÃÂõýàÃÂõÃÂÃÂõ÷ýÃÂüø.
ÃÂÃÂôð öõ ýðü ÃÂõÿõÃÂàøôÃÂø?
ÃÂÃÂðú, ÃÂÃÂþ-ÃÂþ òÿþûýõ ÃÂðñþÃÂþÃÂÿþÃÂþñýþõ àýðàõÃÂÃÂà(ÃÂü. ÃÂøÃÂÃÂýþú). ÃÂþ úðú òàüþöõàôþóðôðÃÂÃÂÃÂÃÂ, ýðÃÂð óþÃÂÃÂõòðàþÃÂõýàôðûõúð þàÃÂþòõÃÂÃÂõýÃÂÃÂòð. çÃÂþ õÃÂõ üþöýþ ÃÂôõûðÃÂÃÂ? ÃÂÃÂ, ýðÿÃÂøüõÃÂ, ÃÂð÷ñøÃÂàýð ÃÂÃÂÃÂðýøÃÂÃÂ. ÃÂþúð ÃÂþþñÃÂõýøù ò ýõù ñÃÂôõàýõ ñþûÃÂÃÂõ ôÃÂöøýÃÂ, ÃÂþùôõàø ÃÂðú. àúþóôð øàÃÂøÃÂûþ ôþùôõàôþ ÃÂþÃÂýø, ÃÂþ ÃÂõôúøù ÿþûÃÂ÷þòðÃÂõûàôþöôõÃÂÃÂàþúþýÃÂðýøà÷ðóÃÂÃÂ÷úø òÃÂõàôðýýÃÂà. ÃÂþöýþ ôðÃÂàÿþûÃÂ÷þòðÃÂõûÃÂü òþ÷üþöýþÃÂÃÂàøÃÂÿþûÃÂ÷þòðÃÂàýõúþÃÂþÃÂÃÂõ HTML-ÃÂõóø, ÃÂÃÂþñàøàÃÂþþñÃÂõýøàòÃÂóûÃÂôõûø ñþûõõ úÃÂðÃÂþÃÂýþ. ÃÂþöýþ ôþñðòøÃÂàÃÂüðùûøúþò... àüþöýþ ôðöõ ÃÂôõûðÃÂàüþôÃÂûàðôüøýøÃÂÃÂÃÂøÃÂþòðýøÃÂ, ÿþ÷òþûÃÂÃÂÃÂøù ÃÂõôðúÃÂøÃÂþòðÃÂàøûø ÃÂôðûÃÂÃÂàÃÂþþñÃÂõýøÃÂ, ð ÃÂðúöõ þÃÂòõÃÂðÃÂàýð ýøà. âðú ÃÂÃÂþ ÃÂðñþÃÂàýõÿþÃÂðÃÂÃÂù úÃÂðù. ÃÂõÃÂ÷ðùÃÂõ â ýõ ñÃÂôàòðü üõÃÂðÃÂÃÂ.
ÃÂõúþÃÂþÃÂÃÂõ ÃÂðÃÂÿÃÂþÃÂÃÂÃÂðýÃÂýýÃÂõ MIME-ÃÂøÿÃÂ
MIME-ÃÂøÿ | ÃÂÿøÃÂðýøõ |
---|---|
text/plain | ÃÂÃÂþÃÂÃÂþù ÃÂõúÃÂà|
text/html | HTML-ÃÂÃÂÃÂðýøÃÂð |
image/gif | ÃÂ÷þñÃÂðöõýøõ GIF |
video/mpeg | ÃÂøôõþ-ÃÂðùû ò ÃÂþÃÂüðÃÂõ MPEG |
application/msword | ÃÂþúÃÂüõýàMS Word |