sutee
sutee

Reputation: 12828

Mako variable not being passed into pyramid form properly

I have a mako form that includes a variable to be passed in as the value for a hidden form tag. Somehow, the variable is not being passed properly. This code has been working before, but now the html generated does not render the value properly.

Mako code:

<b>Create model at path</b>: ${ppath}
<%def name="direct_load_model_form(method, ppath)">
${h.tags.form(method, multipart=True, method='post', hidden_fields=[('ppath', ppath)])}
<b>Node Name: </b>${h.tags.text('node_name')}<BR>
<b>Parameters: </b>${h.tags.file('params_file', size=100)}<BR>
${h.tags.submit('submit', 'Create')}
${h.tags.end_form()}
</%def>

${self.direct_load_model_form(process_route, ppath)}

The hidden_fields function is from the web helpers library. In my views, I am trying to use ppath as ppath = self.request.POST['ppath'].

The ppath variable renders correctly in the first line but not when passed as the value to a hidden field. Do I need to escape it another time or something?

This is the html rendered:

<input type="hidden" value="" name="ppath">

Upvotes: 0

Views: 514

Answers (1)

Lo&#239;c Faure-Lacroix
Lo&#239;c Faure-Lacroix

Reputation: 13600

Here is something you could try, instead of using ppath everywhere, you could rename ppath in your def function to path.

<b>Create model at path</b>: ${ppath}

<%def name="direct_load_model_form(method, path)">
   ${h.tags.form(method, multipart=True, method='post', hidden_fields=[('ppath', path)])}
   <b>Node Name: </b>${h.tags.text('node_name')}<BR>
   <b>Parameters: </b>${h.tags.file('params_file', size=100)}<BR>
   ${h.tags.submit('submit', 'Create')}
   ${h.tags.end_form()}
</%def>

${self.direct_load_model_form(process_route, ppath)}

It might be an issue but since mako creates python code, it's possible that somewhere, the parameter sent to your function is being overriden. That said it's unclear which variable it will use since defs can access global variables but you reset while calling the def.

Upvotes: 1

Related Questions