forms

Empty results in dynamical form in Django

Empty results in dynamical form in Django Question: My views.py: from django.shortcuts import render from django.shortcuts import HttpResponse from .models import * from .forms import TestForm from django import forms def TestView(request,id): test = Tests.objects.get(id=id) queshions = Queshions.objects.filter(test=test) form = TestForm(queshions=queshions) if request.method == ‘POST’: print(request.POST) form = TestForm(data=request.POST, queshions=queshions) print(form) print(form.is_valid()) else: context = …

Total answers: 1

How can i send form by type into input using htmx?

How can i send form by type into input using htmx? Question: I have a search input and sort select. I wrapped it into form. How can i send form by typing into search input (hx-trigger="keyup changed delay:150ms") or selecting another item in select (hx-trigger="changed"). I need to send data from both of this elements. …

Total answers: 1

Django Bootstrap Search Bar on Navigation Bar

Django Bootstrap Search Bar on Navigation Bar Question: I have made a search bar on the navigation bar. What I want to do is I can directly search it on the search bar on navigation bar, then when I hit the search button, it show show the result. However, when I search it, it has …

Total answers: 2

How to prevent django fields from being wrapped in a `div`?

How to prevent django fields from being wrapped in a `div`? Question: If I use the below to generate multiple radio buttons: from django import forms class MCQCollectionForm(forms.Form): user_input = forms.ChoiceField( widget=forms.RadioSelect, label=”, choices=enumerate([‘option 1’, ‘option 2’]) ) I get: <div id="id_user_input"> <div> <label for="id_user_input_0"><input id="id_user_input_0" name="user_input" required="" type="radio" value="0"> option 1</label> </div> <div> <label …

Total answers: 1

Can not validate the AuthForm

Can not validate the AuthForm Question: I’m developing the Login view of my app, in order to do that I used the Django’s built-in authentication form, but when I try to validate the form it returns False and I don’t know why. I let here my code… models.py class User(AbstractUser): ”’ Model that represents a …

Total answers: 2

Django class-based form with dropdowns populated with data from model / db

Django class-based form with dropdowns populated with data from model / db Question: This my Django code: forms.py from django import forms class MyForm(forms.Form): name = forms.CharField() location = forms.CharField() views.py class MyFormView(FormView): template_name = ‘form.html’ form_class = MyForm success_url = ‘home’ def get(self, request, *args, **kwargs): form = self.form_class return render(request, ‘form.html’, {‘form’: form}) …

Total answers: 1

Why individually rendered form fields not posting in Django?

Why individually rendered form fields not posting in Django? Question: I have a class based UpdateView that works fine if I render the form as {{ form.as_p }}. It updating the values, but looks bad. If I try to render the fields individually it does not updating the values. I can’t figure out how to …

Total answers: 1

File upload not working, nothing gets uploaded

File upload not working, nothing gets uploaded Question: Here’s the model class Document(models.Model): file = models.FileField() The template {% extends ‘another-form.html’ %} {% block content %} <form enctype="multipart/form-data" method="post"> {% csrf_token %} {% bootstrap_field form.files %} <button class="btn btn-success col">Upload</button> </form> {% endblock %} Form class and view: from django import forms from django.urls import …

Total answers: 1