Answer the question
In order to leave comments, you need to log in
Why are bottle requests only GET all the time?
I'm analyzing an example of a to-do application from the site.
Even when I force requests via POST, GET requests still go.
Tell me how to fix?
@route("/new", method=['POST'])
def new_item():
"""
Add a new TODO item
"""
if request.forms.get("save", ""):
new = request.forms.get("task", "")
conn = sqlite3.connect("todo.db")
c = conn.cursor()
c.execute("INSERT INTO todo (task,status) VALUES (?,?)", (new,1))
new_id = c.lastrowid
conn.commit()
c.close()
redirect("/")
else:
return template("new_task.tpl")
Bottle v0.12.13 server starting up (using WSGIRefServer())...
Listening on http://127.0.0.1:8080/
Hit Ctrl-C to quit.
127.0.0.1 - - [10/Feb/2017 09:35:11] "GET /new HTTP/1.1" 405 736
127.0.0.1 - - [10/Feb/2017 09:35:12] "GET /new HTTP/1.1" 405 736
<p>Add a new task to the ToDo list:</p>
<form action="/new" method="POST">
<input type="text" size="100" maxlength="100" name="task">
<input type="submit" name="save" value="save">
</form>
Error: 405 Method Not Allowed
Sorry, the requested URL 'http://127.0.0.1:8080/new' caused an error:
Method not allowed.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question