Lösung: POST mit Flask
Completion requirements
index.html
1 2 3 4 5 6 7 8 9 10 11 |
<html> <body> <form action = "http://localhost:5000/auth/user/login" method = "post"> <p>Enter Name:</p> <p><input type = "text" name = "username" value="testUser"/></p> <p>Enter Password:</p> <p><input type = "password" name = "password" value="testPwd"/></p> <p><input type = "submit" value = "submit" /></p> </form> </body> </html> |
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from flask import Flask, request # Flask constructor takes the name of # current module (__name__) as argument. app = Flask(__name__) # The route() function of the Flask class is a decorator, # which tells the application which URL should call # the associated function. @app.route('/auth/user/login', methods=['POST', 'GET']) def loginUser(): username = request.form['username'] password = request.form['password'] return username + " " + password # main driver function if __name__ == '__main__': # run() method of Flask class runs the application # on the local development server. app.run() |
Last modified: Thursday, 13 October 2022, 9:04 AM