Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_form() missing 1 required positional argument: 'form_class' #71

Open
NhaTrang opened this issue May 24, 2017 · 4 comments
Open

get_form() missing 1 required positional argument: 'form_class' #71

NhaTrang opened this issue May 24, 2017 · 4 comments

Comments

@NhaTrang
Copy link

I cannot find out why I've got this error. Any idea?

Traceback:

File "C:\Python35\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "C:\mysite\quiz\views.py" in dispatch
155. return super(QuizTake, self).dispatch(request, *args, **kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\edit.py" in get
174. return self.render_to_response(self.get_context_data())

File "C:\mysite\quiz\views.py" in get_context_data
191. context = super(QuizTake, self).get_context_data(**kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\edit.py" in get_context_data
93. kwargs['form'] = self.get_form()

Exception Type: TypeError at /hell/take/
Exception Value: get_form() missing 1 required positional argument: 'form_class'

@shivakumargn
Copy link

Django 1.10 seems to have introduced a change that is causing the error.

The get_form inside the view needs to change as below
def get_form(self, form_class=None): if form_class is None: form_class = self.get_form_class()

andreas-magenta added a commit to os2datascanner/os2webscanner that referenced this issue Jan 4, 2018
@ALee008
Copy link

ALee008 commented Jun 4, 2018

Hey,
I got the same problem while migrating to Django 1.11.13. Setting the default to None results in a TypeError 'NoneType' object is not callable.

This is the Traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/q/first/take/

Django Version: 1.11.13
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'quiz',
'multichoice',
'true_false',
'essay')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:

File "C:\Python27\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
249. response = self._get_response(request)

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Python27\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "C:\Python27\lib\site-packages\django_quiz_app-0.5.1-py2.7.egg\quiz\views.py" in dispatch
155. return super(QuizTake, self).dispatch(request, *args, **kwargs)

File "C:\Python27\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)

File "C:\Python27\lib\site-packages\django\views\generic\edit.py" in get
174. return self.render_to_response(self.get_context_data())

File "C:\Python27\lib\site-packages\django_quiz_app-0.5.1-py2.7.egg\quiz\views.py" in get_context_data
190. context = super(QuizTake, self).get_context_data(**kwargs)

File "C:\Python27\lib\site-packages\django\views\generic\edit.py" in get_context_data
93. kwargs['form'] = self.get_form()

File "C:\Python27\lib\site-packages\django_quiz_app-0.5.1-py2.7.egg\quiz\views.py" in get_form
168. return form_class(**self.get_form_kwargs())

Exception Type: TypeError at /q/first/take/
Exception Value: 'NoneType' object is not callable

I tried fixing it by adding these lines in the view:

    if form_class is None:
        form_class = QuestionForm

which results in an AttributeError claiming:
'Question' object has no attribute 'get_answers_list'

Any advice is much appreciated. Thank you.

@jameskomo
Copy link

Django 1.10 seems to have introduced a change that is causing the error.

The get_form inside the view needs to change as below
def get_form(self, form_class=None): if form_class is None: form_class = self.get_form_class()

which function exactly? I am having the same challenge

@jameskomo
Copy link

I cannot find out why I've got this error. Any idea?

Traceback:

File "C:\Python35\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "C:\mysite\quiz\views.py" in dispatch
155. return super(QuizTake, self).dispatch(request, *args, **kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\edit.py" in get
174. return self.render_to_response(self.get_context_data())

File "C:\mysite\quiz\views.py" in get_context_data
191. context = super(QuizTake, self).get_context_data(**kwargs)

File "C:\Python35\lib\site-packages\django\views\generic\edit.py" in get_context_data
93. kwargs['form'] = self.get_form()

Exception Type: TypeError at /hell/take/
Exception Value: get_form() missing 1 required positional argument: 'form_class'

Did you get any solution to this? I have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants