0

I have a create and an update notes views. Each view has the same form to create/update a note.

I was wondering on a good way to render the value of my content only in the update view but not in the create view.

Here what I have today :

<div class="field">
    {{ form.title.label }}
    {% if request.endpoint == 'notes.update' %}
        <div class="control">
            {{ form.title(class="input", value=note.title) }}
        </div>
    {% else %}
        <div class="control">
            {{ form.title(class="input"}}
        </div>
    {% endif %}
</div>

I use a condition on the endpoint to do what I want but I don't think it's a good way to do this.

Thank you for help 🙏

1 Answer 1

1

Populate the form in your endpoint.

form = NotesForm(request.form)
form.populate_obj(note)

There is a solution for dictionaries, too.

form = NotesForm(request.form, data={'title':'Untitled Note'})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.