我是 Django 和 Python 的新手。我想在我的表单中添加一个单选按钮,但它不起作用。
形式.py:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.forms.widgets import RadioSelect
from choicebtn.models import myChoice
class myChoiceForm(UserCreationForm):
name=forms.CharField(max_length=55)
TYPE_SELECT = (('0', 'Female'),('1', 'male'),)
gender=forms.ChoiceField(widgets.RadioSelect(choices=TYPE_SELECT))
class Meta:
model = myChoice
fields = ['name','gender']
Run Code Online (Sandbox Code Playgroud)
模型.py:
from django.db import models
from django.forms.widgets import RadioSelect
from django.urls import reverse
class myChoice(models.Model):
name=models.CharField(max_length=55)
TYPE_SELECT = (('0', 'Female'),('1', 'male'),)
gender=models.CharField(max_length=11,choices=TYPE_SELECT)
Run Code Online (Sandbox Code Playgroud)
这只显示dropdownlist和textbox。它不显示单选按钮。请帮我。