Flask is a web application framework written in Python. Here I created an application using Python and deployed on Heroku.

Click here to launch my demo web app.

Prerequisites

Installation

After installing Python install the other frameworks and libraries listed. You can easily install flask using the following command.

pip install Flask
#pip install <package_name>

Define the structure of your web app

static
    |_main.css
template
    |_display.html
app.py
trending.py
requirements.txt

The static directory contains your CSS files, and the template contains the HTML file, which is used for rendering.

You can create a separate .py file for your logic and other operations or write code in the same app.py I suggest creating a separate file will reduce the confusion.

Step 1:

Create your app.py file

I used the waitress service the reason behind using this library is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library.

Install waitress

pip install waitress

Image for post

app.py

import requests
from flask import Flask, render_template, redirect, url_for, request
from datetime import datetime, timedelta
import time
import json
import os
from trending import get_trending
app = Flask(__name__)
@app.route('/')
def trending():
info = get_trending()
   render_template('display.html', info=info['data'])
return res
if __name__ == "__main__":
     app.debug = False
     port = int(os.environ.get('PORT', 33507))
     waitress.serve(app, port=port)

#machine-learning #heroku #flask #python #data-science

Create and Deploy your First Flask App using Python and Heroku
2.85 GEEK