Django - Render radioselect in template

I am working on rendering form in django template and I have a radio field for gender how do i render it in webpage.I tried the following but it raises error.

forms.py

CHOICES = (('1', 'First',), ('2', 'Second',)) gender = forms.CharField(widget=forms.RadioSelect, choices=CHOICES) 

views.py

form = StaffForm(request.POST) return render(request, 'registration.html', {'form':form}) 

html

<label for="form.gender.id_for_label">Gender:</label><br> {{form.gender}} {{form.gender.error}} 

and the following occure

    Unhandled exception in thread started by <function wrapper at 0xb6861d84> Traceback (most recent call last):   File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper     fn(*args, **kwargs)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run     self.check(display_num_errors=True)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check     include_deployment_checks=include_deployment_checks,   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks     new_errors = check(app_configs=app_configs)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config     return check_resolver(resolver)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver     for pattern in resolver.url_patterns:   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__     res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__     res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module     return import_module(self.urlconf_name)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module     __import__(name)   File "/home/loop/workspace/dataschool/dataschool/urls.py", line 23, in <module>     url(r'^account/', include('account.urls')),   File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include     urlconf_module = import_module(urlconf_module)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module     __import__(name)   File "/home/loop/workspace/dataschool/account/urls.py", line 3, in <module>     from . import views   File "/home/loop/workspace/dataschool/account/views.py", line 4, in <module>     from .forms import StaffForm   File "/home/loop/workspace/dataschool/account/forms.py", line 3, in <module>     class StaffForm(forms.Form):   File "/home/loop/workspace/dataschool/account/forms.py", line 12, in StaffForm     gender = forms.CharField(widget=forms.RadioSelect, choices=CHOICES)   File "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py", line 229, in __init__     super(CharField, self).__init__(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument 'choices' 

Replay

Category: python Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.201 (s). 12 q(s)