如何从服务器端的网页保存文档?

时间:2018-05-28 21:47:01

标签: python apache server

我正在使用apache和python来运行我的网页。但是当我尝试保存即时生成的txt文件时,文件也不会被保存。

def save(req):

try:  
    fe1=req.form['fe1']  
    fe2=req.form['fe2']  
    file=open("file.txt",'w')  
    file.write("%s %s" %(fe1,fe2))  
    file.close()  
except KeyError:  
    fe1=''  
    fe2=''  
view="""
    <!DOCTYPE html>
    <html>
        <head>

        </head>
        <body>
            <form method=post action="#">
                <input type='text' id='fe1'></input>
                <input type='text' id='fe2'></input>
                <input type='submit'>
            </form>
        </body>
    </html>
""".format(**locals())

return (view)

在我提交表格后,我得到了这个:

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

File "/usr/lib64/python2.7/site-packages/mod_python/apache.py", line 399, in HandlerDispatch
result = obj(req)
  File "/usr/lib64/python2.7/site-packages/mod_python/publisher.py", line 222, in handler   published = publish_object(req, object)

File "/usr/lib64/python2.7/site-packages/mod_python/publisher.py", line 446, in publish_object     return publish_object(req, util.apply_fs_data(obj, req.form, req=req))

File "/usr/lib64/python2.7/site-packages/mod_python/util.py", line 642, in apply_fs_data     return object(**args)

File "<string>", line 5, in save

IOError: [Errno 13] Permission denied: 'file.txt'

0 个答案:

没有答案