4

So basically I have two functions

@app.route('/index', methods=['GET'])
def do_stuff1():
    *LOGIC*
    return (render_template('index.html', data=data))

and

@app.route('/index', methods=['GET'])
def do_stuff2():
    *LOGIC*
    return (render_template('index.html', moreData=moreData))

How do I pass through the data from the second function to the the same template because it's not working as I have specified there. I'm only getting the first functions data.

EDIT: I should have specified that I want to use the data within the same route.

4
  • 7
    The 2 functions share the same route. To reach the second one, attach it to a different route. Commented Mar 14, 2016 at 13:18
  • 1
    But I want to use both of them within the same route. I'd prefer to keep the logic separated hence the two different functions? If this is possible. Commented Mar 14, 2016 at 13:22
  • 2
    data and moreData should be produced by two standard (undecorated) functions. Then write a third method with the app.route decorator that calls each of them and merges their returns. Commented Mar 14, 2016 at 13:37
  • Ok thank you very much. Appreciate both of your help! Commented Mar 14, 2016 at 13:40

1 Answer 1

4

Your second function does not have to be a 'view' but just a plain python function. Unless I'm missing something...

@app.route('/index', methods=['GET'])
def do_stuff1():
    *LOGIC*
    moreData = do_stuff2()
    return render_template('index.html', data=data, moreData=moreData)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for this! Only wish I would have seen this about 6 hours earlier!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.