0

I got a bunch of variables and would like to return with Flask. However, as you can see, I typed a long list, which seems stupid. May I know if there is any smarter way to deal with this? Thank you in advance.

return render_template('after.html',
    Char1=Char1,
    Char2=Char2,
    Char3=Char3,
    Char4=Char4,
    Char5=Char5,
    Char6=Char6,
    Char7=Char7,
    Char8=Char8,
    graphJSON1 = graphJSON1, 
    graphJSON2 = graphJSON2)
Isaac Tai
  • 59
  • 2
  • 1
    some ideas: https://stackoverflow.com/questions/12096522/pass-variables-to-flasks-render-template – Carlo Jul 11 '22 at 14:30
  • 1
    "I typed a long list, which seems stupid" - no, your problem is exactly that you didn't type a `list`. If you have multiple variables with numbers in them, that's a sign to use lists (as in, object of type list). – h4z3 Jul 11 '22 at 14:32

1 Answers1

1

I suggest you put these values in a dictionary and then access this dictionary in you page

your_char_dict = {[1,Char1],[2,Char2],[3,Char3]}
your_graph_JSON = {"graphJSON1": graphJSON1, "graphJSON2": graphJSON2}

return render_template('after.html', your_char_dict, your_graph_JSON)

But note, that this might not work out of the box

NivisPluma
  • 68
  • 6