0

I'm pretty new to this and I have a python algorithm which I want to run with two parameters that I get from an html form. Here is my html code:

<form action="result/">
      <p><input class="w3-input w3-padding-16" method = "post" type="text" placeholder="Playlist URI" required name="URI"></p>
      <p><input class="w3-input w3-padding-16" method = "post" type="text" placeholder="Spotify Username" required name="Username"></p>
      <p>
        <button class="w3-button w3-light-grey w3-padding-large" type="submit">
          <i class="fa fa-paper-plane"></i> Submit
        </button>
      </p>
    </form>

It redirects me to http://127.0.0.1:5000/result/?URI=b&Username=c, when I input b and c into the form.

I can't figure out how to accept them as parameters though, and it just returns this error:

404 Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

My python code looks like this:

@app.route('/result.html/<URI>&<username>')
def result(URI,username):
    return render_template("result.html", uri=URI, username=username)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
alessoo
  • 11
  • 2
  • Does this answer your question? [How do you access the query string in Flask routes?](https://stackoverflow.com/questions/11774265/how-do-you-access-the-query-string-in-flask-routes) – python_user May 08 '21 at 13:46

1 Answers1

0

you can access parameters in get request using request in flask

example:

from flask import Flask, request

app = Flask(__name__)

@app.route("/result.html")
def result():
    uri = request.args.get("uri")
    username = request.args.get("username")

  • Thanks this worked, I can display the inputs on my result page. I want to use the variables uri and username I pull from the html form to run in my python algorithm and then display the results on the result page. Where would I paste my algorithm and use the uri and username within it? This is my flask code, can I just paste the code for my algorithm under def result? Or should it be in the result.html or elsewhere?: @app.route('/result/') def result(): uri = request.args.get("URI") username = request.args.get("Username") return render_template("result.html", URI = uri, USER=username) – alessoo May 10 '21 at 12:21
  • Can I use {% my algorithm code in python... %} or something like that – alessoo May 10 '21 at 12:39
  • no it is always recommended to do processing in your code not in template – Bhagyajkumar Bijukumar May 11 '21 at 08:13