#๐ web app for school causing me 400 errors
64 messages ยท Page 1 of 1 (latest)
@gray cliff
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.
@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\
Hey @gray cliff!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
<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
Just from a glance is your code definitely sending the request to the right endpoint?
it should be. the form has the action 'delete' which goes to @app.route('/delete', methods=['post'])
Maybe create a /test one that prints any data posted to it
i know i just created the delete one. but im tired and my brain is pulling blanks. can you help me with that
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
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)
are there any messages in the browser devtool
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
i mean. i have instructions. but they kinda leave me to my own devices for how to figure it out
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
I hate when places make you used browser based tools. I tend to write and test my code locally and just paste it in
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
Doss the form need to be /delete
Or flask just delete?
the action should just need to be 'delete'
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
do you get limited tries?
might as well try doing "/delete" instead of "delete" to check
i can test my code as many times as i want. when i click' mark as completed' is when i cant go back
can you also show the example code they provided above this?
here is the database im working with aswell
ive noticed that you have a "delete.html", were you supposed to write anything there?
the completed functions are suppossed to be examples to work with(/submenu, /add, /menu, etc.)
doesnt seem to be the case
can you show those?
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
they are in the photos of server.py
the def name??
The function name yeah
still the same
Fair enough. Change it back
i did
fuck i figured it out
dish = flask.request.args['dish']
was suppossed to be
dish = flask.request.form['dish']
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.