python中怎么创建配置文件_如何在Django中创建配置文件注册表单?
我試圖創(chuàng)建一個定制的注冊表單,但是我不知道如何去做,因為我試圖將默認的django注冊與一個新的模型連接起來。在
這是它看起來的樣子,可能是錯的,但我正在考慮這樣的事情。在
模型.pyclass Profile(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=20, blank=True, null=True)
description = models.TextField(max_length=400)
視圖.py
^{pr2}$
表單.pyclass MyRegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = {'username', 'password1', 'password2', 'email'}
def save(self, commit=True):
my_user = super(MyRegistrationForm, self).save(commit=False)
my_user.email = self.cleaned_data['email']
new_profile = Profile(user=my_user, name="John", description="a person")
if commit:
new_profile.save()
return new_profile
寄存器.py
{% csrf_token %}
{{ form.username.errors }}
{{ form.username.label_tag }}
{{ form.username }}
[... other fiels ...]
我試圖將模型與表單連接起來,所以當有人注冊時,當我在模板中輸入他的名字時,應該是“John”。在
我怎樣才能達到這個目標?在
總結
以上是生活随笔為你收集整理的python中怎么创建配置文件_如何在Django中创建配置文件注册表单?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java里a和b哪个大_Java中 a+
- 下一篇: 计算机user用户的密码存储在,wind