0

I created an app that moves the largest files from the chosen folder to a new folder for inspection. I tried to create an interface for it using django and when I asked my friend, who is fluent in python about the architecture, he said I don't really need a database, so I should rather try flask. In a flask tutorial, I found the guy is actually using SQLAlchemy and is creating a database. How can I pass HTML input to my python omitting database? The pure python app I have already created works just fine without any database.

HTML input section:

{% block body %}
  <h1>Your computer can run faster today</h1>
  <p>You just need to remove the largest files from some of your folders. It's easy with this small project. Enjoy :)</p>
  <form>
    <label for="fname">Path to the folder you want to remove largest files from:</label><br>
    <input type="text" id="fname" name="fname"><br>
    <label for="lname">Path to the folder you want to put your removed files for inspection</label><br>
    <input type="text" id="lname" name="lname">
  </form>
{% endblock %}

Python input section:

print("Type a path to the folder you want to remove the largest files from") 
path1 = os.path.abspath(input())
print("Type a path to create a folder for the largest files to inspect them before removing")
path2 = os.path.abspath(input())
path3 = path2 + '/ToBeRemoved'
Swantewit
  • 966
  • 1
  • 7
  • 19
  • @monsieuralfonse64 - maybe my understanding of the topic wasn't so thorough to use the proper keywords to find the answer? Why do I get negative reputation for being a noob? – Swantewit Sep 27 '20 at 07:25
  • I didn't downvote, I just made it clearer for other users to understand your question by re-formatting your code. – monsieuralfonse64 Sep 27 '20 at 11:30

1 Answers1

1

The most basic Flask app to achieve this will look something like this.

from flask import Flask, request, render_template
app = Flask(__name__)

@app.route('/')
def remove_large_files():
    if request.method == 'POST':
        path_from = request.form.get('fname')
        path_to = request.form.get('lname')

        if path_from and path_to:
            # process your files
            
            # return a response

    return render_template('template.html')

Replace template.html by the template that contains your form.

Refer to the Request object docs for more info.

Simeon Nedkov
  • 1,097
  • 7
  • 11