Héllo Sola,

Can you post the full stacktrace not only the error?


Regards

On Mon Feb 16 2015 at 11:20:42 AM Sola Chong <sola1...@gmail.com> wrote:

> I having a error "*expected string or buffer*" when submit to upload
> avatar when edit profile. Can't figure out what is the problem..
>
> *Model:*
> class MyProfile(models.Model):
>     user = models.ForeignKey(User)
>     dob = models.DateField(null=True, blank=True)
>     address = models.CharField(max_length=100, blank=True)
>     contact = models.CharField(max_length=50, blank=True)
>     bio = models.TextField(blank=True)
>     avatar_url = FileField(_("Avatar"), max_length=200, format="Image",
>  upload_to='user/avatar', blank=True)
>     banner_url = FileField(_("Cover"), max_length=200, format="Image",
>  upload_to='user/cover', blank=True)
>     created = models.DateTimeField(auto_now_add=True)
>     last_modified = models.DateTimeField(auto_now=True)
>
> *Forms:*
> class UserModelForm(forms.ModelForm):
>     class Meta:
>         model = User
>         fields = ('first_name', 'last_name', 'email')
>         widgets = {
>             'email': forms.TextInput(attrs={'readonly':'readonly'}),
>         }
>
>
> class UserProfileModelForm(forms.ModelForm):
>     dob = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'),
>                                input_formats=('%d/%m/%Y',),
>                                required=True, help_text='dd/mm/yyyy')
>     avatar_url = forms.FileField()
>
>     class Meta:
>         model = MyProfile
>         fields = ('dob', 'address', 'contact', 'bio', 'avatar_url')
>
>
> *Views:*
> def editProfileView(request, template="controlpanel/cp_edit_profile.html"
> ):
>
>     myprofiles = MyProfile.objects.all()
>     myprofile = get_object_or_404(myprofiles, user=request.user)
>
>     if request.method == "POST":
>         form = UserProfileModelForm(request.POST, request.FILES, instance=
> myprofile)
>         userForm = UserModelForm(request.POST, request.FILES, instance=
> request.user)
>
>         if form.is_valid() and userForm.is_valid():
>             user = userForm.save()
>             profile = form.save(commit = False)
>             profile.user = user
>             profile.save()
>
>
>             info(request, _("Successfully Edit"))
>     else:
>         userForm = UserModelForm(instance=request.user)
>         form = UserProfileModelForm(instance=myprofile)
>
>
>     context = {"cpprofile": myprofile, 'userForm':userForm, 'form':form}
>
>     return render(request, template, context)
>
> *Template:*
> <form method="post" action="/editprofile" enctype="multipart/form-data">
>             <fieldset>
>             <legend>{{ title }}</legend>
>             {% fields_for userForm %}
>             {% fields_for form %}
>             <div class="form-actions">
>                 {% block account_form_actions %}
>                 <input class="btn btn-primary btn-lg pull-right" type=
> "submit" value="Submit">
>                 {% endblock %}
>             </div>
>             </fieldset>
> </form>
>
>
> Thank you in advance...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c34f91dc-20a8-4195-ba8d-134287e1f9ae%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c34f91dc-20a8-4195-ba8d-134287e1f9ae%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL7_Mo8weKby069OsM9s2nUu9Zr61N8%2BLYLO01smCese-s%2Bo7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to