Django 3 - 水平对齐单选按钮

时间:2021-03-08 13:31:54

标签: django django-models django-forms django-templates

我已经在 Django3 中创建了用户注册表。

在表单中,我想为用户提供一个基于单选按钮的选择。

forms.py 看起来像

   class SignUpForm(UserCreationForm):
   ....
       subscription_choice = (
        ('yearly', 'Yearly'),('monthly', 'Monthly'),
        )

    subscription_type  = forms.TypedChoiceField(
    choices = subscription_choice,
    widget = forms.RadioSelect(attrs={
        "style": "display: inline-block"
    })

模型文件看起来像。

class SignUp(AbstractBaseUser):

    subscription_choice = (
        ('yearly', 'Yearly'),('monthly', 'Monthly'),
        )

    email = models.EmailField(unique=True)
    firstname = models.CharField(max_length=150)
    lastname = models.CharField(max_length=150)
    phonenumber = models.CharField(max_length=14,primary_key=True)
    referral_code = models.CharField(max_length=150, default="None")
    subscription_type = models.CharField(max_length=10, default="monthly", choices=subscription_choice)
    ....
    

我尝试了一些关于 SO 的答案中建议的 css 技巧,但没有成功。

我得到的结果是垂直对齐(凌乱)的单选按钮。

enter image description here

需要一些帮助。

0 个答案:

没有答案
相关问题