Flask Framework in Python


Flask was created by Armin Ronacher of Pocoo, an international group of Python enthusiasts formed in 2004.Initial Release 1st April 2010.

Flask is an open source micro-framework for Python. It does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components.

Applications that use the Flask framework include Pinterest and LinkedIn.

The microframework Flask is based on the Pocoo projects.

  • Web Server Gateway Interface (WSGI)
  • Jinja Template Engine
Advantages
  • Easy to code.
  • Easy to configure.
  • Has an excellent documentation.

Source Code

App.py
from flask import Flask, render_template, request
app = Flask(__name__)

@app.route('/')
@app.route('/register')
def homepage():
    return render_template('register.html')

@app.route("/confim", methods=['POST', 'GET'])
def register():
    if request.method == 'POST':
        n = request.form.get('name')
        a = request.form.get('age')
        c = request.form.get('city')
        return  render_template('confirm.html',name=n,age=a,city=c)

if __name__ == "__main__":
    app.run(debug=True)
register.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Registration</title>
</head>
<body>
<form action="/confim" method="post">
    <label>Name</label>
    <input type="text" name="name">
     <label>Age</label>
    <input type="text" name="age">
     <label>City</label>
    <input type="text" name="city">
    <input type="submit" value="Register">
</form>
</body>
</html>
confim.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register Success</title>
</head>
<body>
<h3>Registration Success</h3>
<table>
     <tr>
         <td>Name</td><td>{{name}}</td>
     </tr>
     <tr>
         <td>Age</td><td>{{age}}</td>
     </tr>
     <tr>
        <td>City</td><td>{{city}}</td>
     </tr>
 </table>
</body>
</html>
MySQL Client Wheel Click Here To download raw file Click Here

Learn All in Tamil © Designed & Developed By Tutor Joes