please make sure you have corrected like this
*setting.py*
============
MEDIA_ROOT = '*site_media*' #make sure your have it already!!!!!! and it's
your problems also
TEMPLATE_DIRS = (
    'templates',
)
============
*models.py*
=================
from django.db import models
class photos(models.Model):
    caption = models.CharField(max_length=10)
    photo  = models.ImageField(upload_to= 'images/photo')
==================
*views.py*
==================
from django.forms import ModelForm
from django import forms
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from djangotest.upload.models import photos
from django.core.urlresolvers import reverse

class MyForm(ModelForm):
    class Meta:
        model = photos

def upload(request):
    if request.method == "POST":
        form = MyForm(request.POST, request.FILES) #make sure this line
        if form.is_valid():
            sheet = form.save()
            return HttpResponseRedirect(reverse('upload_thanks'))

    return render_to_response(
        "upload.html",
        {
            "form" : MyForm(),

        }
    )
===================
*urls.py*
====================
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # ...
    url(
        r'^upload/$',
        'upload.views.upload',
        name="upload"
    ),
    url(
        r'^upload/thanks/$',
'django.views.generic.simple.direct_to_template',
        { 'template' : 'upload_thanks.html' },
        name="upload_thanks"
    ),
)
======================
create in templates folder (template folder the same directory the
applications not project in sample code)
======================

<form id="uploadForm" enctype="multipart/form-data" action="."
method="POST">
  <table>
    {% for field in form %}
      <tr>
        <td>
        </td>
        <td>
            {{ field.errors }}
        </td>
      </tr>
      <tr>
        <td class="label">
          {{ field.label_tag }}:
        </td>
        <td>
          {{ field }}
        </td>
      </tr>
    {% endfor %}
  </table>

  <input type="submit" value="Upload" />
</form>
======================
!!!!! you see in the template form the *action *='.' it will store the photo
in * site_media/image/photo/*

my folder structure :
uploadtest-->myproject
    -upload -->my application
         -template -->my template folder
         -site_media -->my site media to store the files such as photos.
Hope it can help you.
from* KSO.*

On Wed, Apr 29, 2009 at 3:26 AM, Aaron <
substantialnoninfringingu...@gmail.com> wrote:

>
> Hey, this looks like the same problem I had earlier. The gotcha was
> that I needed enctype="multipart/form-data" in my form tag, like <form
> enctype="multipart/form-data" action="" method="post">
>
> Hope this isn't too late!
>
> Aaron
>
> On Mar 9, 5:34 am, Marek Wawrzyczek <mwawrzyc...@gmail.com> wrote:
> > Hi,
> >
> > I've got the code like this:
> >
> > class Photo(models.Model):
> >     image = models.ImageField(upload_to='photos')
> >
> > class PhotoForm(ModelForm):
> >     class Meta:
> >         model = Photo
> >
> > View function fragment:
> >
> >     if request.method == 'POST':
> >         post = request.POST.copy()
> >         print 'post: %s' % post
> >         photoForm = PhotoForm(post)
> >         if photoForm.is_valid():
> >             print 'photoForm valid'
> >             photoForm.save()
> >         else:
> >             print 'photo form is invalid'
> >         return render_to_response(template_name, {'photoForm' :
> photoForm})
> >     else:
> >         photoForm = PhotoForm()
> >         return render_to_response(template_name, { 'photoForm' :
> photoForm})
> >
> > Template fragment:
> >
> >  <form id="photoForm" method="POST" action=".">
> >                     <ul class="errorlist">
> >                     </ul>
> >                     {{photoForm.non_field_errors}}
> >                     {{ photoForm.as_p }}
> >                 <input type="submit" value="dodaj zdjecie"/>
> >             </form>
> >
> > Through the admin interface, I can add new photos, but when I try to add
> > it through the page, then the
> > "This field is required." message is posted, and the output on the
> > console is:
> >
> > post: <QueryDict: {u'image': [u'abc.gif']}>
> > photo form is invalid
> >
> > When I try to use FileField it works the same. How can I slove this
> > problem ?
> >
> > Regards,
> > Marek
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to