Python flask forward array as string into URL variable

Viewed 18

I am looking to give an array as a string to a URL variable. e.g.

arr = np.arange(10)
arrs = 'np.array('+np.array2string(arr,separator=',')+')'

This gives the output

>>> 'np.array([0,1,2,3,4,5,6,7,8,9])'

Now I would like to give this value to my URL, so that the form can read it out later.

</form>

<form method=post action="{{ url_for('plot',formid=2, arr={{arrs}}) }}">
<input type="text" name="projectFilepath" value='submitted string'>

<p><input type=submit value=Study!></form>

Which should send us to something like http://127.0.0.1:5000/plot?formid=2&arrs='np.array([0,1,2,3,4,5,6,7,8,9]')

Then one can grab the variable and read it with say arrs = exec(x).

However, if I try to plug arrs into the URL I get the following error. I'm guessing it's something small, but I am not sure why it is not working.

<form method=post action="{{ url_for('plot',formid=2, arrs={{arrs}}) }}">
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'

Does anybody know what I am doing wrong?

0 Answers
Related