I'm a beginner at Flask. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Asked 2 years ago, Updated 2 years ago, 99 views

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


@app.route("/hello/", methods=['POST','GET'])
def profile(username=None):
    error = None
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        if not username and not email:
            return add_profile(request.form)
    else:
        error='Invalid username or email'

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

Code from the Flask book.

It's almost the beginning Run and move on to /profile/.

Not Found

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

The error appears.

Actually, I don't understand the code well, so I can't solve the error and I'm stuck.

Please give me some information from a kind developer who can explain what code that code is and how it works.

python flask

2022-09-22 15:05

1 Answers

@app.route("/hello/", methods=['POST','GET']) I'm using a decoration called route. It is to designate the service url.

You should call /hello, which is declared in route, not profile.

The above code will perform a function called profile when /hello is called, and the method will only allow POST and GET.

HTTP 1.1 methods include PUT, DELETE, HEAD, OPTIONS, and TRACE instead of POST and GET.

However, the more problematic thing is that we need more supplies (input forms) to perform the above code. The above code has an input form and the input form has fields called username and email, which are the logic that is performed (registered) when you fill in the value and submit.


2022-09-22 15:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.