Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django genecric.FormView: 'NoneType' object is not callable

I’m trying to render a really basic FormView but it says it can’t get the form model. Full error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/edit.py", line 144, in get
    return self.render_to_response(self.get_context_data())
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/edit.py", line 74, in get_context_data
    kwargs["form"] = self.get_form()
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/edit.py", line 39, in get_form
    return form_class(**self.get_form_kwargs())

Exception Type: TypeError at /new-game/
Exception Value: 'NoneType' object is not callable

Form:

class NewGameForm(ModelForm):
    class Meta:
        model = models.Game
        fields = ['title', 'bank_money', 'player_starting_money', 'golden_card_amount']

View:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class NewGameView(generic.FormView):
    template_name = 'games/create_game.html'
    form = forms.NewGameForm

Note that django development server is running on a linux docker container with python 3.10.7

>Solution :

The form class of a FormView is given by the form_class class attribute, not form.

class NewGameView(generic.FormView):
    template_name = 'games/create_game.html'
    form_class = forms.NewGameForm

See Form handling with class-based views

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading