Skip to content

Commit

Permalink
Add HTTP redirection with variable setting example
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jun 27, 2019
1 parent 62d2297 commit 75dd3ce
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def internal_redirection_manual(number: int):


@hug.post()
def redirect(redirect_type: hug.types.one_of((None, "permanent", "found", "see_other")) = None):
def redirect(redirect_type: hug.types.one_of(("permanent", "found", "see_other")) = None):
"""Hug also fully supports classical HTTP redirects,
providing built in convenience functions for the most common types.
"""
Expand All @@ -38,3 +38,10 @@ def redirect(redirect_type: hug.types.one_of((None, "permanent", "found", "see_o
hug.redirect.to("/sum_two_numbers")
else:
getattr(hug.redirect, redirect_type)("/sum_two_numbers")


@hug.post()
def redirect_set_variables(number: int):
"""You can also do some manual parameter setting with HTTP based redirects"""
print("HTTP Redirect set variables {}".format(number))
hug.redirect.to("/sum_two_numbers?number_1={0}&number_2={0}".format(number))

0 comments on commit 75dd3ce

Please sign in to comment.