0

I am trying to a assign a value to a WTForm field within the HTML template. I need to do it this way as the value assigned will depend on what iteration of the for loop it is in. Any other way of passing a value back to the python script will work as well.

I am currently getting an error. I am trying to assign the record field of the form equal to the id of the record it is currently viewing.

Below is the code:

<div class="modal-body"> <p>Name of Training: {{ record.training_name }}</p> <p>Name of Provider: {{ record.training_provider }}</p> <p>Date of Training: {{ record.date_submitted.strftime('%d/%m/%Y') }}</p> <p>CPD Hours: {{ record.cpd }}</p> <p>Certificate: <a href="{{ url_for('static', filename='certificates/'+record.certificate_path) }}" target="_blank">View</a></p> <form action="" method="post"> {{ form.hidden_tag() }} <fieldset> <div class="form-group"> {{ form.reason(class="form-control", placeholder="Reason for Denial (if applicable)") }} {% set form.record.data=record.id %} </div> </fieldset> 

When attempting to use the solution above I am getting the following error: jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '.'

1 Answer 1

1

If I'm understanding you correctly:

{{ form.record(value=record.id, class="d-none") }} 

instead of

{% set form.record.data=record.id %} 
Sign up to request clarification or add additional context in comments.

2 Comments

This is good, but the field shows this way. I want it to be hidden
I'm assuming you're using bootstrap with the form-control class. Add d-none to have the field hidden

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.