[Python] Is it possible to get data from HTML page to the server side using a hidden field...

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    Hi guys Here's the problem I'm using a fast render form using Bootstrap-Flask that contains a hidden field and I want to get back a record ID through it but of course,e I can't write simple Jija2 in it because I can't access it from the HTML page or that what I think here's what I have and some solutions I tried (note: I know that if used a different way of rendering the form will be easier to handle this but the core of the question is there a way to do that while using fast render**)**

    this is the form

    class TaskForm(FlaskForm):
    title = StringField(label="Task Title", validators=[DataRequired()])
    description = CKEditorField(label="Description", validators=[DataRequired()])
    list_id = HiddenField(
    label="List id",
    validators=[DataRequired()],
    default="{{list.id}}",
    )
    submit = SubmitField("Add task")


    I have a container of todo list that I iterate through it

    {% for list in all_lists %}
    <li class="list col col-sm-3 justify-content-start">

    <h5 class="card-title text-muted text-uppercase text-start">
    {{ list.title }}
    </h5>
    <p style="display: none">{{ list.description }}</p>
    <hr />
    <ol class="fa-ol ol-task justify-content-start">
    {% for task in list.ltasks %}
    <!-- Cards to do-->
    <li class="task justify-content-start">
    <h6 class="card-title text-muted text-uppercase text-start" >
    {{ task.title }}
    </h6>
    <hr />
    <p class="card-text">{{ task.description }}</p>
    </li>
    {% endfor %}
    <li class="task justify-content-start">
    {{ ckeditor.load(pkg_type="basic") }}
    {{ ckeditor.config(name='body') }}
    {{ render_form(task_form ,novalidate = True, id = "task-form" ) }} <-- Fast rendered form -->
    </li>
    </ol>
    </li>
    {% endfor %}


    So I have tried to pass the default attribute as seen above and also used render_kw={"value":"{{ list.id }}"} I even tried to the field using javascript and append it to the form which has worked but the list.id only shows up as a string like this:

    <input id="list_id" name="list_id" required="" type="hidden" value="{{list.id}}">


    and also tried to pass it with different styles like (list.id), and (List.id) with a capital L like the DB class itself, I even tried to pass (db.get_or_404(List,>id<) but remembered that I need the id :D

    I am still learning and knowing the nooks and crannies is part of the quest Thanks in advance

    Continue reading...

Compartilhe esta Página