[英]Django: ImageField Unknown Field
I currently have a django project I am working on and I extended the user profile successfully, however I would like to allow the user to have a profile picture so I added the following code: Models.py: 我目前正在处理一个django项目,并且成功扩展了用户个人资料,但是我希望允许用户拥有个人资料图片,因此我添加了以下代码:Models.py:
profile_pic = models.ImageField(upload_to='img/profile/%Y/%m/')
and in my forms.py 和我的forms.py
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('profile_pic')
and here is the code for my views: 这是我的观点的代码:
@login_required
def user_profile(request):
if request.method == 'POST':
form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/profile')
else:
user = request.user
profile = user.profile
form = UserProfileForm(request.POST or None, instance=profile)
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('profile.html', args)
However when I go to the profile page now, I am presented with the following: 但是,当我现在进入个人资料页面时,会看到以下内容:
Django Version: 1.6.2
Django版本:1.6.2
Exception Type: FieldError
异常类型:FieldError
Exception Value:
异常值:
Unknown field(s) (profile_pic) specified for UserProfile
为UserProfile指定的未知字段(profile_pic)
Any ideas? 有任何想法吗? I am pretty new to the django framework.
我对Django框架很陌生。 Thank you
谢谢
fields = ('profile_pic')
逗号不必是fields = ('profile_pic',)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.