-3

I'm trying to create a webpage in html in which a user have to input a url into a textfield.

<form name="submitURL" method ="post">
<input type="text" name="url_target">
<button type="submit">submit</button>

When the user press the submit button a python script should intercept the data inserted by the user and pass it to another function inside this script.

Python script:

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/')
def indhtml() :
   return render_template('index.html')

@app.route('/index.html', methods = ['POST'])
def result():
    result = request.form('url_target')
    link = result.link
    print (link)
    return

if __name__ == '__main__' :
    app.run(debug = True)

the first render is fine and i can see the index.html page, but when i insert something in the textfield appears the error HTTP 405.

Do you have any suggestion for that? :( Thanks!

2
  • 1
    This is Flask, not Django. Oct 21, 2017 at 13:13
  • Thanks for the annotation Daniel, I'm learning both these days and I made confusion while writing :)
    – ySlag
    Oct 21, 2017 at 13:15

2 Answers 2

1

You forgot action="{{ url_for('result') }}" in your <form> tag, so you are submitting the form to the same page, which is not accepting POST requests.

Additionally, request.form is dict-like, so you need [] and not () to access it. link = result.link is going to fail too because there is no way that link attribute exists on the string you get from request.form...

0
1

Your function result() returns nothing.

1
  • The point is not that i suppose.. I mean, the function will return the url in future, but the error remains even if i add something to return
    – ySlag
    Oct 21, 2017 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.