#πŸ”’ In flask a redirect in a seperate function won't work what should I return?

15 messages Β· Page 1 of 1 (latest)

gusty scarab
#
def redirect_function()
     # code 
     # redirects to a route


@app.something(/'something')
def something():
    # code
    redirect_function
    # code             

Now obviously this won't work because of the return redirect... in the redirect_function() .
Does anyone have any suggestions on what I should return instead of return redirect... in the def redirect_function() ?

mint emberBOT
#

@gusty scarab

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.

torpid beacon
#
  @app.something(/'something')
  def something():
      # code
-     redirect_function
+     return redirect_function()
      # code 
gusty scarab
#

but then I can't write any code after return redirect_function()

#

or am I mistaken

#

would yield work instead of return

#

?

errant solar
#

Why do you need to run code after a redirect? Can you return the redirect after running all the code you want?

gusty scarab
#

I wanted to divide my code into smaller chunks

#

so it is more if something happens then redirect

torpid beacon
#

For example,

@app.something(/'orders/{order_number}')
def get_order(order_number)
  order = get_order_from_database(order_number)
  if not order:
    abort(404)
  return order
gusty scarab
#

Thanks for the help okay I get it now

mint emberBOT
#
Python help channel closed for inactivity

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.