-1

I am trying to learn flask. My login.html file-

<html>  
   <body>
      <form action = "http://localhost:5000/login" method = "post">    
         <table>  
        <tr><td>Name</td>  
        <td><input type ="text" name ="uname"></td></tr>  
        <tr><td>Password</td>  
        <td><input type ="password" name ="pass"></td></tr>  
        <tr><td><input type = "submit"></td></tr>  
    </table>  
      </form>  
   </body>  
</html>

And my main.py file has this-

@app.route('/login',methods = ['POST'])  
def login():
    uname=request.form['uname']  
    passwrd=request.form['pass']  
    if uname=="ayush" and passwrd=="google":  
        return "Welcome %s" %uname

I am not able to understand how is this able to access login.html without specifying. Also also please explain what is the code in main.py means.

Dheeraj-Tech
  • 33
  • 2
  • 10

1 Answers1

0

You have to specify the 'html' in flask to access it, however, if you open the html file in browser this will still work since its action is aimed directly at your flask server.

the code of your main.py says that if the in the form sent the data 'uname' and 'pass' are respectively 'ayush' and 'google', the code sends back to the browser a text indicating: "Welcome ayush"

If you want to directly implement the html in your flask web server, you have to create the function and put your html code in templates folder.

from flask import render_template
...

@app.route('/', methods=['GET'])
def code():
    return render_template('index.html', name='')

So you can access with http://localhost:5000/ now

gaetan1903
  • 34
  • 3