M
M
maqstein2019-02-14 00:13:10
Flask
maqstein, 2019-02-14 00:13:10

Why does sending a POST request to flask redirect me to fu.Php?

in general, there is such a code

import os
from app import app
from flask import Flask,render_template,request,flash,redirect,url_for
from config import Configurations
from werkzeug.utils import secure_filename

app.secret_key = b'hul'

@app.route('/dz',methods=['GET','POST'])
def index():
    error = None
    if request.method == 'POST':
        if 'file' not in request.files:
            error = 'слышь,файл выбери!'
            #return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            error = 'слышь,файл выбери!'
            #return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            #return redirect(url_for('uploaded_file',
            #                        filename=filename))
        return render_template('index.html',error = error)
    return render_template('index.html')

I start, check the page, everything is fine ,
but
after I pressed the button for the post request
5c6487929833d518389594.png5c64879b3742f383995006.png
on the server, php is not even installed,
why does it work like that?
HTML:
<!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
    <form method=post enctype=multipart/form-data>
      <input type=file name=file>
      <input type=submit value=Upload>
    </form>
{{ error }}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-02-25
@maqstein

At you action in the form is not specified, therefore the browser and sends where without getting. If you would draw the form and send it to the template from the view, then the action would not be needed, but you will have to write it that way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question