Yeah, if in doubt you can use the forms.as_p first to see what kind of
html form it outputs and use that as the basis for creating your form.

On Thu, Oct 30, 2008 at 7:05 PM, Giles Thomas
<[EMAIL PROTECTED]> wrote:
>
> please smile wrote:
>>         Can anybody please tell how to upload a image ?
>
> I'm new to this myself, but I got something working using Django's forms
> mechanism.
>
> My view function looks something like this:
>
> -------------------------------
> class MyForm(ModelForm):
>    class Meta:
>        model = photos
>
> def upload(request):
>    if request.method == "POST":
>        form = MyForm(request.POST, request.FILES)
>        if form.is_valid():
>            sheet = form.save()
>            return HttpResponseRedirect(reverse('upload_thanks'))
>
>    return render_to_response(
>        "upload.html",
>        {
>            "form" : MyForm(),
>        }
>    )
> -------------------------------
>
> This is then rendered by a template, upload.html, that looks something
> like this:
>
> -------------------------------
> <form id="uploadForm" enctype="multipart/form-data" action="{% url
> upload %}" 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>
> -------------------------------
>
> Finally, my urls.py specifies "names" for both the upload and the
> upload_thanks pages:
>
> -------------------------------
> urlpatterns = patterns('',
>    # ...
>    url(
>        r'^upload/$',
>        'my.app.views.upload',
>        name="upload"
>    ),
>    url(
>        r'^upload/thanks/$',
> 'django.views.generic.simple.direct_to_template',
>        { 'template' : 'upload_thanks.html' },
>        name="upload_thanks"
>    ),
> )
> -------------------------------
>
> Hope this helps.
>
>
> Cheers,
>
> Giles
>
> --
> Giles Thomas
> MD & CTO, Resolver Systems Ltd.
> [EMAIL PROTECTED]
> +44 (0) 20 7253 6372
>
> Try out Resolver One! <http://www.resolversystems.com/get-it/>
>
> 17a Clerkenwell Road, London EC1M 5RD, UK
> VAT No.: GB 893 5643 79
> Registered in England and Wales as company number 5467329.
> Registered address: 843 Finchley Road, London NW11 8NA, UK
>
>
>
> >
>



-- 
Low Kian Seong
blog: http://lowkster.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to