0

Everytime I run flask run and go to the website, I cant see any of the input fields. Instead, I get the message 'must contain a number'.What am I doing wrong?

{% extends "layout.html" %}

{% block title %}
    water use
{% endblock %}

{% block main %}
    <form action="{{ url_for('wateruse') }}" method="post, get">
        <h2>Please input a number and select an option. All fields have to be filled out.</h2>
        <div class="form-group" style="background-color: #0019ff">
            <label for="bathtube">bathtube</label>
            <select class="form-control" id="bathtube" name="bathtube">
                <option value="">Select a bathtube</option>
                {% for stock in stocks %}
                    <option value="{{ stock.bath_tube }}">{{ stock.bath_tube }}</option>
                {% endfor %}
            </select>
            <input class="form-control" id="bath" name="bath" placeholder="number of baths" type="number">
        </div>
        <div class="form-group" style="background-color: #003fff">
            <label for="wc">Toilette</label>
            <input class="form-control" id="wc" name="wc" placeholder="time of using the WC" type="number">
        </div>
        <div class="form-group" style="background-color: #0061ff">
            <label for="dishwasher">dishwasher</label>
            <option value="">Select a diswasher</option>
            {% for dis in di %}
                <option value="{{ dis.dishwasher }}">{{ dis.dishwasher }}</option>
            {% endfor %}
            <input class="form-control" id="dishwasher" name="dishwasher" placeholder="times of using the dishwasher" type="number">
        </div>
        <div class="form-group" style="background-color: #0081ff">
            <label for="washing machine">washing maschine</label>
            <select class="form-control" id="washing_machine" name="washing_machine">
                <option value="" >select a washing machine</option>
                {% for wams in wam %}
                    <option value="{{ wams.name }}">{{ wams.name}}</option>
                {% endfor %}
            </select>
            <input class="form-control" id="was" name="was" placeholder="times of using the washing machine" type="number">
        </div>
        <div class="form-group" style="background-color: #009eff">
            <label for="shower">shower</label>
            <input class="form-control" id="shower" name="shower" placeholder="minutes I showered" type="number">
        </div>
        <div class="form-group" style="background-color: #009bff">
            <label for="water use">washing up</label>
            <input class="form-contol" id=" water_use" name="water_use" placeholder="minutes I washed up stuff" type="number">
        </div>
        <div>
            <button class="btn btn-primary" type="submit">Submit</button>
        </div>
    </form>
{% endblock %}

@app.route('/wateruse', methods=["GET", "POST"])
@login_required
def wateruse():

    stocks = db.execute("SELECT * FROM bathtube")
    di = db.execute("SELECT * FROM dishwasher")
    wam = db.execute("SELECT * FROM washing_maschine")

    if request.method == "POST" or "GET":
        b = request.form.get("bathtube")
        wm = request.form.get("washing_machine")
        d = request.form.get("dishwasher")
        s = request.form.get("shower")
        wa = request.form.get("water_use")
        t = request.form.get("wc")
        bath = request.form.get("bath" )
        was = request.form.get("was")

        if not b or not wm or not d or not s or not wa or not t or not bath or not was:
            return 'must contain a number'

        db.execute("INSERT INTO water_use (user_id, bathtube, wc, washing_maschine, dishwasher, timestamp,  wash_time, shower_time) VALUES (:user_id, :bath,:.wc, :wm, :d, :t, :was, :s) WHERE user_id = :user_id",
            user_id=session["user_id"],
            bathtube=b,
            wc=t,
            washing_maschine=wm,
            dishwasher=d,
            wash_time=wa,
            shower_time=s,
            )

        bat = db.execute("SELECT UNIQUE litre FROM bathtube WHERE bath_tube = :bathtube", bathtube=b)
        bat = bat * bath

        diwa = db.execute("SELECT UNIQUE litre FROM dishwasher WHERE dishwasher = : dishwasher", dishwasher=d)
        diwa = diwa *d

        wama = db.execute("SELECT UNIQUE litre FROM washing maschine WHERE name= :washing_machine", washing_machine=wm)
        wama = wama * was


        toi = db.execute("SELECT UNIQUE water_use FROM d_table WHERE name=wc")
        toi = toi * t

        sho = db.execute("SELECT UNIQUE water_use FROM d_table WHERE name=shower")
        sho = sho * s

        waup = db.execute("SELECT UNIQUE water_use FROM d_table WHERE name=tap")
        waup = waup * wa

        total = bat + toi + diwa + wama + sho +waup

        db.execute("INSERT INTO water_use (total) VALUE (:total) WHERE user_id = :user_id", total=total, user_id=session["user_id"] )


        flash(f"You used {total} litre of water")
        return redirect(url_for("/wateruse", stocks=stocks, di=di, wam=wam))
1
  • Start by validating the HTML as with NuValidator. From a quick read the "method" attribute on the "form" element is invalid. Dec 1, 2023 at 14:05

0

You must log in to answer this question.

Browse other questions tagged .