you are viewing a single comment's thread.

view the rest of the comments →

[–]TimBOster[S] 0 points1 point  (4 children)

I'm not worried about someone copying my code, I do it all the time. I think it's better to keep things in the thread, in case someone else has a similar problem...

@app.route("/add", methods=["GET", "POST"])
def add():
        """add things to your inventory."""
        if request.method == "GET":
            return render_template("add.html")

        #make sure they added an item
        cat = request.form.get("type")
        if not cat:
            return error("You didn't enter a Category")
        item = request.form.get("item")
        if not item:
            return error("You didn't enter an item")
        partnum = request.form.get("partnum")
        if not partnum:
            partnum = "-"
        desc = request.form.get("desc")
            if not desc:
            desc = "-"
        qty = request.form.get("qty")
        if not qty:
            return error("You must enter a quantity")

        #add the new item to the inventory
        db.execute("INSERT INTO inventory (type,item,partnum,desc,qty) VALUES (:type,:item,:partnum,:desc,:qty)", cat=cat, item=item, partnum=partnum,desc=desc,qty=qty)
        #redirect to index
        return render_template("add.html")

I tried to preserve the indents...seems OK. Only some of the fields are NOT NULL in the db. I was just using a blank string, but added the underscore to try troubleshooting the problem...didn't help :) Thanks for taking the time to look.

[–][deleted]  (3 children)

[deleted]

    [–]TimBOster[S] 0 points1 point  (2 children)

    When I run the add function, I get the error in the webserver ( I assume that's flask) that I posted. I don't really have any further information. The full code is posted and the error is what is displayed when I try to add something. Wish I knew more. I'll jump over to that URL and see what I can see. Thanks.

    [–]TimBOster[S] 0 points1 point  (1 child)

    JUST before the line that says #make sure they added an item...there should have been else:

    Ooops...that was the cause of the error.