Python – Spell Checker using Flask + TextBlob + Bootstrap 4

Hello everyone, In this tutorial, we will show you how to develop the simple spell checker application using Flask, TextBlob and Bootstrap 4. The example program has been tested and shared in the post.

Flask Service Layer

from flask import Flask, render_template, request
from textblob import TextBlob

app = Flask(__name__)


@app.route('/')
def home():
    return render_template('index.html')


@app.route('/correct', methods=['POST'])
def correct():
    if request.method == 'POST':
        input = request.form['input']
        text = TextBlob(input)
    return render_template('index.html', input=text, output=text.correct())



app.run()


Flask View Layer

<html>

    <head>
        <title>Spell Checker</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    </head>

    <body class="container">

        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
          <a class="navbar-brand" href="#">Spell Checker</a>
        </nav>

        <div class="row justify-content-center">
            <div class="col-11">
                <form action="/correct" method="post">
                    <div class="form-group">
                        <label for="input">Input</label>
                        <textarea class="form-control" id="input" name="input" rows="5">{{ input }}</textarea>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">Correct</button>
                        <button type="reset" class="btn btn-danger">Clear</button>
                    </div>

                    <div class="form-group">
                        <label for="output">Output</label>
                        <textarea class="form-control" id="output" name="output" rows="5">{{ output }}</textarea>
                    </div>
                </form>
            </div>
        </div>

    </body>

</html>

Output

Spell Checker using Flask + TextBlob + Bootstrap 4

References

  1. http://flask.pocoo.org/
  2. https://getbootstrap.com/
  3. https://textblob.readthedocs.io/en/dev/