Данные POST недоступны на Python Flask при работе на сервере Ubuntu (приложение работает без проблем при локальном запуске) - PullRequest
0 голосов
/ 09 января 2020

У меня есть форма HTML, которая позволяет пользователю вводить некоторые данные,

<form  enctype="multipart/form-data" action="/index" method="post" >
  <br>
    <div class="row">
    <div class="col">
      <input type="text" class="form-control" name = "campaign_name" placeholder="Campaign Name" required>
    </div>

    <div class="col">

Затем у меня есть функция Python, которая обрабатывает входные данные из HTML форма. При локальном запуске я могу получить доступ к данным POST. Однако при запуске того же приложения на сервере Ubuntu Apache печать метода request.method показывает только запросы GET, обслуживаемые моим Flask бэкэндом.

@app.route('/', methods=['GET', 'POST'])
def index():
    print(request.method)
    if request.method == 'POST':

        # check if the post request has the file part
        if 'myfile' not in request.files:
            print(request.files)
            print("no file part")
            flash('No file part')
            return render_template('index.html')
        file = request.files['myfile']
        if file.filename == '':
            print("empty file name")

            flash('Error! No file selected for uploading')
            return render_template('index.html')

Я в замешательстве, поскольку могу получить доступ к данным POST локально, но не могу этого сделать при запуске моего приложения в Ubuntu

Вот фрагмент моего файла conf:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName www.segmentation-module.com
        ServerAlias segmentation-module.com
        ServerAdmin webmaster@segmentation-module.com
        #       ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html


        WSGIDaemonProcess segmentationmodule threads=5 python-home=/home/ubuntu/segmentationmodule/env
        WSGIScriptAlias / /var/www/html/segmentationmodule/segmentationmodule.wsgi

        <Directory segmentationmodule>
            WSGIProcessGroup segmentationmodule
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
        </Directory>


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Вот фрагмент моего wsgi:

python_home = '/home/ubuntu/fbads/env'

activate_this = python_home + '/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import sys
sys.path.insert(0, '/var/www/html/segmentationmodule')
from segmentationmodule import app as application

Пожалуйста, предложите, что может быть не так. Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...