Re: Help to Upload image

2008-11-01 Thread Low Kian Seong

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:
>
> ---
> 
>  
>{% for field in form %}
>  
>
>
>
>{{ field.errors }}
>
>  
>  
>
>  {{ field.label_tag }}:
>
>
>  {{ field }}
>
>  
>{% endfor %}
>  
>
>  
> 
> ---
>
> 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! 
>
> 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
-~--~~~~--~~--~--~---



Re: Help to Upload image

2008-10-30 Thread Giles Thomas

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:

---

  
{% for field in form %}
  



{{ field.errors }}

  
  

  {{ field.label_tag }}:


  {{ field }}

  
{% endfor %}
  

  

---

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! 

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



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help to Upload image

2008-10-30 Thread please smile
Hi All,
Can anybody please tell how to upload a image ?
models.py

class photos(models.Model):
caption = models.CharField(max_length=10)
photo  = models.ImageField(upload_to= 'Path')

It works at Admin Side .But not working at client side.

MyHtml.html





Caption :

 





Image :

 





 

 







What would be the views.py code ?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---