Flask

less than 1 minute read

Published:

This post covers introduction to Flask!

Hello Flask!

/* static/style.css */
h1{
  color: red;
}

.other{
  color: blue;
}
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Hello Flask</title>
    
    <link rel="stylesheet" href="{{url_for('static', filename='style.css')}}">
    
  </head>

  <body>
    <h1> Welcome to Index Page </h1>
    
    <a href="{{url_for('other')}}"class='other'>Click for other page </a>
    
  </body>
  
</html>

<!-- templates/other.html -->
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Hello Flask</title>
    
    <link rel="stylesheet" href="{{url_for('static', filename='style.css')}}">
    
  </head>

  <body>
    <h1 class='other'> Welcome to Other Page </h1>
    
    <a href="{{url_for('index')}}">Click for index page </a>
    
    
  </body>

</html>

# hello_flask.py

# import Flask and render_template
from flask import Flask, render_template

# Create web application by creating Flask instance
Flask_App = Flask(__name__)

@Flask_App.route('/')
def index():
    page = render_template('index.html')
    return page

  
@Flask_App.route('/other')
def other():
    page = render_template('other.html')
    return page

  
if __name__ == '__main__':
    Flask_App.debug = True
    Flask_App.run()