#๐Ÿ”’ web app for school causing me 400 errors

64 messages ยท Page 1 of 1 (latest)

gray cliff
#

current assignment is being tough because it seems like im using the wrong variable, but i cant figure out which one to use

fresh folioBOT
#

@gray cliff

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gray cliff
#
@app.route('/delete', methods=['POST'])
def delete_item():
    dish = flask.request.args['dish']
    ditem = where(db_from('items'), 'Name', dish)
    delete('items', ditem[0])
    return flask.render_template('delete.html', 
                                deleted_item=ditem[0],
                                sections=get_sections(),
                            dish_names=get_dish_names())

is the current handler function\

fresh folioBOT
#

Hey @gray cliff!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
gray cliff
#
<form action='delete' method='POST'>
    <select name='dish_item'>
        {% for dish in dish_names %}
        <option value='{{dish}}'>{{dish}}</option>
        {% endfor %}
    </select>
    <input type='submit' value='delete dish'>
</form>
```is the html form
#
<body>
        <h1>Welcome to Cafe HTML</h1>
        <p> You have removed <b>{{deleted_item['Name']}}</b> from the menu!</p>
        {% include 'form.html' %}
    </body>
```body of delete.html
#

im getting a 400 error(bad request) when i try to delete anything

austere storm
#

Just from a glance is your code definitely sending the request to the right endpoint?

gray cliff
#

it should be. the form has the action 'delete' which goes to @app.route('/delete', methods=['post'])

austere storm
#

Maybe create a /test one that prints any data posted to it

gray cliff
#

i know i just created the delete one. but im tired and my brain is pulling blanks. can you help me with that

austere storm
#

400 looks to be a routing error. I've not used flask before but I've used similar libraries in other languages

Maybe see if there's a way to run code on requests before you route them. If you know where your form is sending the data you can figure out what you need to change

gray cliff
#

yeah, i tried making the test route. and still getting the bad request

#

@app.route('/test')
def teststuff():
a = flask.request.args['test']
return a

<form action='test'>
<input type='text' value='test'>
<input type='submit' value='submit'>
</form>

#

(those are in seperate files ofc)

mystic pilot
#

are there any messages in the browser devtool

austere storm
#

There's an issue with your routing. I'm not familiar enough with flask to other suggestions

The best thing I can suggest is to read the documentation for routing

Also please use codeblocks

gray cliff
mystic pilot
#

no really

#

are there messages in browser devtools

gray cliff
#

i dont know what that means

#

im sorry

mystic pilot
#

ok

#

what browser are you using?

#

on firefox and chrome type Ctrl + Shift + I

gray cliff
#

its one with the schools website. the website uses something called 'codio' which seems to have a browser built in. i havent learned about devtools yet so i highly doubt they would write anything in there

mystic pilot
#

i see

#

you are just typing code into codio and it does the thing for you?

gray cliff
#

pretty much. i also have files to manage and all that

austere storm
#

I hate when places make you used browser based tools. I tend to write and test my code locally and just paste it in

gray cliff
#

also everytime i try to use the stuff i made i just get '[25/Aug/2025 06:37:18] "POST /delete HTTP/1.1" 400'

#

not an actual error message

#

which i hate

austere storm
#

Doss the form need to be /delete

Or flask just delete?

mystic pilot
gray cliff
austere storm
#

It'll be something like that more than likely. My advice is read the documentation for routing using flask. Your course is probably expecting you to do your own research and learn more than what they explicitly teach

mystic pilot
#

might as well try doing "/delete" instead of "delete" to check

gray cliff
mystic pilot
# gray cliff

can you also show the example code they provided above this?

gray cliff
mystic pilot
#

ive noticed that you have a "delete.html", were you supposed to write anything there?

gray cliff
austere storm
# gray cliff

Humor me for a second and change delete_item to delete

That's the only one where the route doesn't match the function name

gray cliff
austere storm
#

The function name yeah

gray cliff
#

still the same

austere storm
#

Fair enough. Change it back

gray cliff
#

i did

#

fuck i figured it out

#

dish = flask.request.args['dish']
was suppossed to be
dish = flask.request.form['dish']

mystic pilot
#

ahhh

#

nice

gray cliff
#

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

#

!close

fresh folioBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.