我想在用户注册页面时添加一个下拉列表,显示使用 PYtZ 包的公共时区。要注册用户,我正在使用 UserCreationForm 类。代码如下:
class UserRegisterForm(UserCreationForm):
email2 = forms.EmailField(label=_("E-mail"))
def clean_email2(self):
email2 = self.cleaned_data['email2']
try:
user = User.objects.get(email=email2)
except User.DoesNotExist:
return email2
raise forms.ValidationError(_("Account with this e-mail address already exists."))
def save(self, commit=True):
user = super(UserRegisterForm, self).save(commit=False)
user.email = self.cleaned_data["email2"]
user.is_active = False
if commit:
user.save()
return user
我正在使用以下命令获取所有常用时区的列表:
>>> from pytz import timezone
>>> import pytz
>>> print(pytz.common_timezones)
它打印: http: //pastebin.com/RHdie16M
我也知道选择字段,但使用它不是一个好主意。我该怎么办?