[Python] How to create a form Django (names and elements) from a column of a DataFrame or...

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    How can I create a form - even if it's not a Django form, but a regular one via input? So that the names and elements of the form fields are taken from a column of a DataFrame or QuerySet column. I would like the form fields not to be set initially, but to be the result of data processing - in the form of data from a column of a DataFrame or QuerySet column. The name of the form fields to fill in from the data in Views.

    Maybe send a list or a single DataFrame or QuerySet to the template via JINJA?

    from django import forms

    # creating a form
    class InputForm(forms.Form):

    first_name = forms.CharField(max_length = 200)
    last_name = forms.CharField(max_length = 200)
    roll_number = forms.IntegerField(
    help_text = "Enter 6 digit roll number"
    )
    password = forms.CharField(widget = forms.PasswordInput())

    from django.shortcuts import render
    from .forms import InputForm

    # Create your views here.
    def home_view(request):
    context ={}
    context['form']= InputForm()
    return render(request, "home.html", context)

    <form action = "" method = "post">
    {% csrf_token %}
    <table>
    {{ form.as_table }}
    </table>
    <input type="submit" value="Submit">
    </form>


    How to create a form Django (names and elements of the form fields) from a column of a DataFrame or QuerySet column.?

    Continue reading...

Compartilhe esta Página