Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

upload py file using flask

from flask import Flask, render_template, request, redirect, url_for
import os
from os.path import join, dirname, realpath

app = Flask(__name__)

# enable debugging mode
app.config["DEBUG"] = True

# Upload folder
UPLOAD_FOLDER = 'static/files'
app.config['UPLOAD_FOLDER'] =  UPLOAD_FOLDER


# Root URL
@app.route('/')
def index():
     # Set The upload HTML template '	emplatesindex.html'
    return render_template('index.html')


# Get the uploaded files
@app.route("/", methods=['POST'])
def uploadFiles():
      # get the uploaded file
      uploaded_file = request.files['file']
      if uploaded_file.filename != '':
           file_path = os.path.join(app.config['UPLOAD_FOLDER'], uploaded_file.filename)
          # set the file path
           uploaded_file.save(file_path)
          # save the file
      return redirect(url_for('index'))

if (__name__ == "__main__"):
     app.run(port = 5000)
Comment

upload html file using flask

<!doctype html>
<html>
  <head>
    <title>FLASK CSV File Upload</title>
  </head>
  <body>
    <h1>Upload your CSV file</h1>
    <form method="POST" action="" enctype="multipart/form-data">
      <p><input type="file" name="file"></p>
      <p><input type="submit" value="Submit"></p>
    </form>
  </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Python :: django creating calculated fields in model 
Python :: how to transpose a 2d list in python 
Python :: python not jump next line 
Python :: shutil remove 
Python :: find null values pandas 
Python :: how to draw a rectangle in pygame 
Python :: reverse text python 
Python :: pygame music player 
Python :: add custom field to serializer 
Python :: python plot 
Python :: pathlib get extension 
Python :: how to practise python 
Python :: how to write to the end of a file in python 
Python :: python ieee 754 converter 
Python :: sort dict by value 
Python :: python numpy array to list 
Python :: how to import date python 
Python :: python instagram downloader 
Python :: python float to 2 decimals 
Python :: update set python 
Python :: packing and unpacking in python 
Python :: plt.imshow not showing image 
Python :: create alinked list inb pyhton 
Python :: how to check if an input is a string in python 
Python :: os system python 
Python :: read specific rows from csv in python 
Python :: python datetime strftime 
Python :: numpy roundup to nearest 5 
Python :: how to find the location of a character in a string in python 
Python :: how to determine python project parent dir 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =