How do I call a python function with parameters in CGI?

人盡茶涼 提交于 2019-12-11 04:32:06

问题


I want to build an interface for browsing an Apache2 server using python scripts.

I spent the past days learning python and today getting familiar with CGI. I want to test out some stuff, like the possibility for the user to navigate to the path he wants from the base directory

/var/www/cgi-bin

by inputting the path he wants to visit, for example

/etc/httpd/conf.d.

For that i have the change_path.py script which looks like this:

import os

def changePath(path):
    os.chdir(path)

I already got this script running to make sure everything is set up properly:

#!/usr/bin/python

# Import modules for CGI handling 
import cgi, cgitb, os 

cwd = os.getcwd()

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>TestScript</title>"
print "</head>"
print "<body>"
print "<h2> Current working directory is: %s</h2>" % cwd
print "</body>"

来源:https://stackoverflow.com/questions/45213148/how-do-i-call-a-python-function-with-parameters-in-cgi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!