开发者

Calling .php within a Django/Python file

I am building an application in Django and want to run a .php script I alread开发者_JS百科y have made earlier. I need to be able to give along a string to the .php file and catch the returning output. Does anyone have an idea how to do this? Can I make some kind of http request and catch the response?

p.s. I already tried converting the php file to python script but I couldn't get it to work..


try this one, i've found it here

import subprocess

#simple caller, disguard output

subprocess.call("php /path/to/my/old/script.php")

# if you want output

proc = subprocess.Popen("php /path/to/my/script.php", shell=True,
stdout=subprocess.PIPE)

script_response = proc.stdout.read()


If it's a php file served by web server (I assume that from your HTPP request question) do something like this:

In [1]: import urllib2
In [2]: resp = urllib2.urlopen('http://www.starenka.net/ip')
In [3]: resp.read()
Out[3]: 'ip: 62.245.xx.xx\nlocal ip: 62.245.xx.xx\nhostname:  ip-62-245-xx-xx.net.upcbroadband.cz\n'
In [4]: resp.info()
Out[4]: <httplib.HTTPMessage instance at 0x9f8720c>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜