On Fri, Apr 19, 2013 at 3:14 PM, Hélio Miranda <helio...@gmail.com> wrote:
> I'm trying to make a simple uplaod picture but I'm not getting. I'm doing
> the following way:
>
> Models.py:
> class TestUpload(models.Model):
>      model_pic = models.ImageField(upload_to='Temp/', blank=True, null=True)
>
> Forms.py:
> class TestUploadForm(forms.Form):
>     image = forms.ImageField()
>
> Views.py:
> def index(request):
>     if request.method == 'POST':
>         form = TestUploadForm(request.POST, request.FILES)
>         if form.is_valid():
>             form.save()
>             return render_to_response('index.html', {'form': form})
>     else:
>         form = TestUploadForm()
>     return render_to_response('index.html', {'form': form},
> context_instance=RequestContext(request)
>     )
>
> index.html:
>  <!doctype html>
> <html>
>   <head>
>
>   <title>{% block title %}{% endblock %}</title>
>   </head>
>   <body>
>   <marquee>Teste!</marquee>
> {% block content %}{% endblock %}
>     <h1>Inserir</h1>
>     <form action="" method="post" enctype="multipart/form-data">{%
> csrf_token %}
>                 <p>
>                     <input id="id_image" type="file" class="" name="image">
>                 </p>
>                 <input type="submit" value="Submit" id="Save" />
>             </form>
>   </body>
> </html>
>
> But it is not working ... does anyone know what I'm doing wrong?
>

"Not working" is the least descriptive way of telling us what is wrong.

Is the computer plugged in to the wall?
Is the power socket turned on?
....
Does the code run?
Does the form validate when you submit it?
  You could check this by logging that it passes the is_valid check.
Does the form have any errors when it is submitted?
  You could check this by actually outputting the form errors in the template.
Does submitting the form produce an exception?
  We need to see it

Cheers

Tom

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to