2013-02-20 29 views
1

我知道他们已经有很多关于此的帖子,但我尝试了很多解决方案,并且无法显示我的表单!Django用户资料表格清空

我想要做的很简单的东西(我是一个Django初学者),我创建了一个特定的用户配置扩展基本之一,我希望让用户编辑:

这里是我的模型:

class UserProfile(models.Model): 
    user = models.OneToOneField(User) 
    cc = models.CharField(max_length=400, blank=True) 
    lang = models.CharField(max_length=5, blank=True,) 
    def __unicode__(self): 
     return unicode(self.user.email) 

class UserProfileForm(forms.ModelForm): 
    class meta: 
     model = UserProfile 
    def __init__(self,*args,**kwargs): 
     super(UserProfileForm, self).__init__(*args, **kwargs) 
     self.user = kwargs['instance'] 

def create_user_profile(sender, instance, created, **kwargs): 
    if created: 
     UserProfile.objects.create(user=instance) 

post_save.connect(create_user_profile, sender=User) 

这是我的观点方法:

@login_required 
def accountform(request): 
    data = {} 
    data.update(csrf(request)) 
    user_profile = request.user.get_profile() 
    data['form'] = UserProfileForm(instance=user_profile) 
    print user_profile 
    return render(request, 'accountform.html', data) 

这里是我的模板:

<form action="/contact/" method="post"> 
    {{ form.as_p }} 
    <input type="submit" value="Submit" /> 
</form> 

当我显示,从我刚才看到的提交按钮...

+0

一切正常,你有没有错过什么,同时发布? – Rohan 2013-02-20 04:30:35

+0

不,我没有错过任何东西,我现在卡在这... – 2013-02-20 04:44:51

回答

6

meta内部类应该大写 - Meta

class UserProfileForm(forms.ModelForm): 
    class Meta: # not meta 
     model = UserProfile 
+0

Whaou我觉得我应该通过新的眼镜....现在的作品:) – 2013-02-20 04:50:29