If you have a single argument passed in the URL you can do it as follows
from flask import request
#url
http://10.1.1.1:5000/login/alex
from flask import request
@app.route('/login/<username>', methods=['GET'])
def login(username):
print(username)
In case you have multiple parameters:
#url
http://10.1.1.1:5000/login?username=alex&password=pw1
from flask import request
@app.route('/login', methods=['GET'])
def login():
username = request.args.get('username')
print(username)
password= request.args.get('password')
print(password)
What you were trying to do works in case of POST requests where parameters are passed as form parameters and do not appear in the URL. In case you are actually developing a login API, it is advisable you use POST request rather than GET and expose the data to the user.
In case of post request, it would work as follows:
#url
http://10.1.1.1:5000/login
HTML snippet:
<form action="http://10.1.1.1:5000/login" method="POST">
Username : <input type="text" name="username"><br>
Password : <input type="password" name="password"><br>
<input type="submit" value="submit">
</form>
Route:
from flask import request
@app.route('/login', methods=['POST'])
def login():
username = request.form.get('username')
print(username)
password= request.form.get('password')
print(password)