Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5990975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:19:15+00:00 2026-05-22T23:19:15+00:00

Trying to work with ImageField in django. Here are my models class Album(models.Model): title

  • 0

Trying to work with ImageField in django.
Here are my models

class Album(models.Model):
    title = models.CharField(max_length=100)

    def __unicode__(self):
        return self.title

class Photo(models.Model):
    image = models.ImageField(upload_to='photos/')
    album = models.ForeignKey(Album)
    title = models.CharField(max_length=100, default="")

    def __unicode__(self):
        return self.title

class PhotoModelForm(forms.ModelForm):
    class Meta:
        model = Photo

Here is a part of urls.py

...
url(r'^trial/upload/$', 'trial.views.upload'),
...

views.py

def upload(request):
    if request.method == 'POST':
        form = PhotoModelForm(request.POST, request.FILES)
        if form.is_valid():
            photo = form.save()
            return render_to_response('trial/thanks_upload.html',{
                'photo': photo
            }, context_instance = RequestContext(request))
    else:
        form = PhotoModelForm()
    return render_to_response('trial/upload.html', {
      'form': form
    }, context_instance = RequestContext(request))

upload.html

<form enctype="multipart/form-data" action="/trial/upload/" method="post">
    {% csrf_token %}
    {% for field in form %}
        <div class="fieldWrapper">
            {{ field.errors }}
            {{ field.label_tag }}: {{ field }}
        </div>
    {% endfor %}
    <p><input type="submit" value="Upload" /></p>
</form>

But on saving I have next error:
TypeError at /trial/upload/
coercing to Unicode: need string or buffer, tuple found

Errors appears on photo.save

Does anybody has ideas why could it be? Why tuple appears at all? I’m sure there is a stupid bug…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:19:16+00:00Added an answer on May 22, 2026 at 11:19 pm

    I’ve got it myself. In settings.py there is MEDIA_ROOT setting, which was

    MEDIA_ROOT = 'd:/dev/python/scripts/app/media/',
    

    Python makes the object tuple because of the comma at the end. That’s why it couldn’t save the object. Watch your commas next time!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add images to my models in my Django app. models.py class
Programming Student here...trying to work on a project but I'm stuck. The project is
I am trying to work out the best database model for the current setup:
I'm new to Django (and Python) and I have been trying to work out
I am Trying to work through some class examples and have gotten stuck on
I am trying to work out the best way to design a class that
I'm trying to work on a sub-class of System.Web.UI.WebControls.HyperLink in C# and I want
I have been trying to work my way through Project Euler, and have noticed
Weve recently been trying to work on an application that uses pandastream to encode
I'm trying to work through Project Euler and I'm hitting a barrier on problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.