MultiValueDictKeyError when extending django registration 1.0?
I'm using and extending Django registration 1.0. I have a UserProfile
model that has an profile image field using the ThumbnailerImageField from
django easy thumbnails:
class UserProfile(models.Model):
# link to user
user = models.OneToOneField(User, related_name='userprofile')
# other information attributes (first name, last name, gender, avatar,
background image)
firstname = models.CharField(max_length=250,blank=True,null=True)
lastname = models.CharField(max_length=250,blank=True,null=True)
profile_image = ThumbnailerImageField("Profile Pic",
upload_to=content_file_name,
default=settings.STATIC_URL+'images/default-profile.jpg')
In my forms I extend RegistrationForm:
from registration.forms import RegistrationForm
from django import forms
from PIL import Image
class UserProfileForm(RegistrationForm):
profile_image = forms.ImageField(required=True)
And I use signals to create a new UserProfile:
def add_profile_fields(sender, user, request, **kwargs):
try:
profile = user.get_profile()
except UserProfile.DoesNotExist:
profile = UserProfile(user=user)
form = UserProfileForm(request.POST, files=request.FILES)
profile.profile_image = form.data["profile_image"]
profile.save()
user_registered.connect(add_profile_fields)
And I have the following form in my template:
<form method="post" action="." enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
But anytime I try to upload an image I get:
MultiValueDictKeyError at /accounts/register/
"Key 'profile_image' not found in <QueryDict: ...
What can be the problem?
No comments:
Post a Comment