Django Listview FormMixin

1.2k views Asked by At

I am newbie to django sorry if its a silly question, I was trying to use FormMixin in django, but receiving the following error:

  return form_class(**self.get_form_kwargs())
TypeError: 'NoneType' object is not callable

Forms.py

class SubscriberForm(forms.Form):
    email = forms.EmailField(label='',
                             max_length=100,
                             widget=forms.EmailInput(attrs={'class': 'form-control', 'type':'email'}), validators=[validateEmail])

Views.py

from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from .models import Subscriber
from .forms import SubscriberForm
import random
from django.views.generic.edit import FormMixin
from django.urls import reverse

    class NewsletterList(FormMixin, generic.ListView):
        queryset = newsletter.objects.filter(status=1).order_by('-created_on')
        template_name = 'index.html'
        from_class = SubscriberForm
    
    
        def post(self, request, *args, **kwargs):
            form = SubscriberForm(request.POST)
            if form.is_valid():
                sub = Subscriber(email=request.POST['email'], conf_num=random_digits())
                sub.save()
                return render(request, "index.html", {'form': SubscriberForm()}) 
            else:
                return render(request, "index.html", {'form': SubscriberForm()}) 

Can someone help me pls. Thanks in advance

0

There are 0 answers