Why am i not receiving data from my django forms and what shoul i do to fix it?

Hi guys I’m trying to create a form with a dropdown and other fields, I’m trying to get the data from the form but for some reason I’m not getting anything

This the template tha I’m using

{% extends "main_page_layout.dj.html" %}
{% block content %}
<form id="comunicate" method="post">{% csrf_token %}

    <select name="company">
        {% for company in companies %}
            <option value={{company.id}}>{{ company.name }}</option>
        {% endfor %}
    </select>
    <button id="comunicate" type="submit">Submit</button>
</form>
{% endblock %}

I’m using this piece of code to try to get the data from the form but it’s not working

This is the form that I’m using in django

class PruebaForm(forms.Form):
    company = company = forms.ModelChoiceField(
        queryset=CompanyInfo.objects.all(),
        widget=forms.Select(attrs={"hx-get": "/load_users/", "hx-target": "#id_user"}),
        )
    
    user = forms.ModelChoiceField(
        queryset=UserLicense.objects.all(),
    )
    
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['user'].queryset = UserLicense.objects.none()

        if "company" in self.data:
            company_id = self.data.get('company')
            self.fields["user"].queryset = UserLicense.objects.filter(company_id=company_id)

If someone can explain why I’m not getting anything it would be helpful since I’m new with this, it works when i use {{form.as_p}} but the thing is that i have to it manually to
personalize the fields of the form

Here you are trying to iterate it like it’s been passed as context data from view but it is form data and you have to use it like one, that’s the reason when you use {{form.as_p}} this it works.

Also, if you need custom choices for your choice field than you have to integrate it through your forms like

class PruebaForm(forms.Form):
    company = forms.ModelChoiceField(
        queryset=CompanyInfo.objects.all(),
        widget=forms.Select(attrs={"hx-get": "/load_users/", "hx-target": "#id_user"}),
    )

    user = forms.ChoiceField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['user'].choices = [(None, "Select User")] + [(user.id, user.name) for user in Account.objects.all()]

Here I’ve updated user form’s choice you can also do it for any other choices.

Also in the templates if you don’t want to use {{form.as_p}}, you can do something like this

<body>
    {{form.company.label}}
    {{form.company}}

    {{form.user.label}}
    {{form.user}}
</body>