I am creating a foreign exchange currency converter using using Python, Flask, and forex\_python.converter. Right now, when the user submits the currencies and amount to be converted on the home page, it directs them to a separate webpage just showing the values of their form inputs. Eventually this will show the converted Forex amount.

If the user inputs an incorrect forex code or a string as the amount, they would be directed back to the same page and error banners would appear using Flasks's flash messaging. I have been able to successfully create error banners for incorrect Foreign exchange code inputs, however I am struggling with how to create one for an invalid amount. Ideally if the "amount" that the user entered in were letters, blank, or symbols instead of a number, the banner would appear "Not a valid amount." Right now, the banner will always appear, but that the user amount is never converted to a float.

I tried this by converting the user entered amount into a float using `float()`, which worked successfully when the amount was an integer (or float), however if the input was anything else, I receive an error and my code stops. I've been stumped on this for a few hours now, so if anyone has any strategies on how to approach this, I would appreciate it.

My python code and 3 HTML pages are below:

```
from flask import Flask, request, render_template, flash, session, redirect, url_for
from flask_debugtoolbar import DebugToolbarExtension
from forex_python.converter import CurrencyRates

app = Flask(__name__)
app.config['SECRET_KEY'] = "secretkey"

# store all currency rates into variable as a dictionary
c = CurrencyRates()
fx_rates = c.get_rates('USD')

# home page
@app.route('/', methods=['POST', 'GET'])
def home():
    return render_template('home.html')

# result page. User only arrives to result.html if inputs info correctly
@app.route('/result', methods=['POST', 'GET'])
def result():
    # grab form information from user and change characters to uppercase
    forex_from = (request.form.get('forex_from').upper())
    forex_to = (request.form.get('forex_to').upper())

    # Where I am running into issues.
    # I have tried:      
    #      before_amount = (request.form.get('amount').upper())
    #             amount = float(before_amount)
    amount = request.form.get('amount')
    print(amount)

    # if input is invalid bring up banner error
    if forex_from not in fx_rates :
        flash(f"Not a valid code: {forex_from}")

    if forex_to not in fx_rates :
        flash(f"Not a valid code: {forex_to}")

    if not isinstance(amount, float) :
        flash("Not a valid amount.")

    # if any of above errors occur, direct to home, else direct to result.html
    if forex_to not in fx_rates or forex_from not in fx_rates or not isinstance(amount, float):
        return redirect(url_for('home'))
    else :
        return render_template('result.html', forex_from=forex_from, forex_to=forex_to, amount=amount)

```

```html
<!-- Base.html -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/css/bootstrap.min.css" integrity="sha384-DhY6onE6f3zzKbjUPRc2hOzGAdEf4/Dz+WJwBvEYL/lkkIsI3ihufq9hk9K4lVoK" crossorigin="anonymous">
    <title>Forex Converter!</title>
</head>
<body>

{% block content %}
{% endblock %}

</body>
</html>
```

```html
<!-- home.html -->

{% extends "base.html" %}

{% block content %}

<h1>Forex Converter!</h1>
{% for msg in get_flashed_messages() %}
    <div class="alert alert-danger" role="alert">
        <h3>{{msg}}</h3>
    </div>
{% endfor %}
<div class="alert alert-danger d-none" role="alert">
    Not a valid amount.
    </div>
<form action="/result" method="POST">
    <div class="form-group">
        <label for="forex_from">Converting from</label>
        <input name="forex_from" type="text"><br>
    </div>
    <div class="form-group">
        <label for="forex_to">Converting to</label>
        <input name="forex_to" type="text">
        <br>
    </div>
    <div class="form-group">
        <label for="amount">Amount: </label>
        <input name="amount" type="text"><br>
    </div>
    <button type="submit" class="btn btn-primary">Convert</button>
</form>

{% endblock %}
```

```html
<!-- result.html -->

{% extends "base.html" %}

{% block content %}

<h1>Forex Converter!</h1>
<h3>forex_from: {{forex_from}}</h3>
<h3>forex_to: {{forex_to}}</h3>
<h3>amount: {{amount}}</h3>
<form action="/">
    <button type="submit" class="btn btn-primary">Home</button>
</form>

{% endblock %}
```