【发布时间】:2021-07-07 10:13:15
【问题描述】:
我有 Flask 应用程序,它使用 HTML 表单从用户那里获取数据,通过 bash 脚本运行它并通过另一个 HTML 将其返回给用户。如果我通过命令行python3 app.py 运行它,一切正常,但是当它由 NGINX 处理时,request.form.get('email') 中没有数据。
应用程序.py
from flask import Flask, render_template, request
import subprocess
app = Flask(__name__)
app._static_folder = "/home/my_site/templates/static"
@app.route('/', methods = ['GET'])
def show_index_html():
return render_template('index.html')
@app.route('/send_data', methods = ['POST'])
def get_email_from_html():
email = request.form.get('email') ###No data here
output = subprocess.run(['/home/path_to_script/query.sh', email], capture_output=True)
score = output.stdout
return render_template('output.html', output=score)
if (__name__ == '__main__'):
app.run(ssl_context=('mailcheck.crt','mailcheck.key'),host="0.0.0.0", port=8888,debug=True)
索引.html
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8>
<!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">-->
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='main.css')}}">
</head>
<body>
<div class="box">
<form method="POST" action="/send_data">
<div class = "form-group">
<span>E-mail :</span>
<input type="email" class="email_form" name="email" maxlength="30">
</div>
<input type="submit" class="button" value="Send">
</form>
</div>
</body>
</html>
网站.ini
[uwsgi]
module = wsgi:app
master=true
processes = 5
socket = site.sock
chmod-socket = 666
vacuum = true
die-on-term = true
Nginx 服务器块
server {
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name mailcheck.mysite.com www.mailcheck.mysite.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/soc/site/site.sock;
}
}
server {
listen 80;
server_name mailcheck.mysite.com www.mailcheck.mysite.com;
return 301 https://$server_name$request_uri;
}
【问题讨论】: