Skip to content

Commit

Permalink
allow both GET and POST methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Jun 1, 2024
1 parent 40ae7f9 commit 1c984c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/todo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def index():
# example of GET/POST/DELETE RESTful APIs


@action("api") # a GET API function
@action("api", method="GET") # a GET API function
@action.uses(session, db) # we load the session and db
@action.uses(user_in_session) # then check we have a valid user in session
def todo():
Expand Down
4 changes: 3 additions & 1 deletion py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,11 @@ def register_route(app_name, rule, kwargs, func):
else:
rule = url_prefix + rule
dec_func = action.catch_errors(app_name, func)
if "method" not in kwargs:
kwargs["method"] = ["GET", "POST"]
bottle.route(rule, **kwargs)(dec_func)
filename = module2filename(func.__module__)
methods = kwargs.get("method", ["GET", "POST"])
methods = kwargs.get("method")
if isinstance(methods, str):
methods = [methods]
for method in methods:
Expand Down

0 comments on commit 1c984c8

Please sign in to comment.