确定在WSGI Python中从HTML中按下了哪个按钮(没有任何像flask和Django这样的框架)



我正在使用WSGI、python3和apache2在核心python中实现web应用程序。现在我需要根据python WSGI文件中某个按钮的值或id来检测按下了哪个按钮请建议我可以放在WSGI文件中的代码。

Python代码:

def application(environ, start_response):
if environ['REQUEST_METHOD'] == 'POST':
post_env = environ.copy()
post_env['QUERY_STRING'] = ''
post = cgi.FieldStorage(fp=environ['wsgi.input'],
environ=post_env,
keep_blank_values=True
)
html =  page_header + content + page_footer
start_response('200 OK', [('Content-Type', 'text/html')])
return [html.encode('utf-8')]

HTML代码:

<div> 
<form method="post">
<button id="button1">Button1</button>
<input type="text"></input> Status 
<button id="button2">Button2</button>
<input type="text"></input> Status2
</form>
</div> 

我期待着代码的生命

如果"button1":"某些代码"如果"button2":"某些代码">

我使用AJAX将数据从HTML发送到WSGI

HTML代码:

$.ajax(
{
type: "POST",
url: "https://link/sample/",
data: {'param1':"Generate",'param2':htmlTDES},
success: function (html)
{alert("AJAX PASS");},
error: function(request, ajaxOptions, thrownError)
{
alert(thrownError);
}
});

WSGI代码:

if environ['REQUEST_METHOD'] == 'POST':
post_env = environ.copy()
post_env['QUERY_STRING'] = ''
post = cgi.FieldStorage(
fp=environ['wsgi.input'],
environ=post_env,
keep_blank_values=True
)
name = post.getvalue('param1')
htmlTDES = post.getvalue('param2')
if name=="Generate":
Genrate_function()
html =  page_header + content + page_footer
start_response('200 OK', [('Content-Type', 'text/html')]
return [output.encode('utf-8')]

相关内容

最新更新