Monday, May 9, 2011

Re: Image upload from another website using image url

Hi Esam,

first of all:
form = Addpic(request.POST)

Secondly, could you respond to my 3 suggestions, are they clear?

Why would start processing the form before checking if it is valid?

See also:
http://docs.djangoproject.com/en/dev/topics/forms/

Good luck! RR

On May 9, 8:45 pm, esam al deen <ass...@gmail.com> wrote:
> @nederhoed: what i need to to do is allow user to store files from
> anywhere include another web site  , when user give me a file "browse
> button " i  get it and store it, another method that user can give me
> file url >>www.example.com/main.jpg,, i wrote the code that got the
> file and stored it into /tmp ,, how i can assign form.image to this
> stored file ?
> my code again ..
> <input id="id_name" type="text" name="name" maxlength="255"
> value="www.example.com/main.jpg" /> view.py
> def Post_date():
>   if request.method == 'POST':
>      form = Addpic()#simple form to capture data image_url =
>      request.POST.get('image')
>      file = urllib.urlopen(image_url)
>      im = cStringIO.StringIO(file.read()) # constructs a StringIO
> holding the image
>      img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
> '.gif'
>      img.save(save)
>      form.image=save
>   if form.is_valid():
>      pic = form.save(commit=False)
>      pic.save()
>
> models.py
>
> class Pic(models.Model):
>     image = ImageWithThumbsField(upload_to='images', sizes=((128,
> 128),))
> The image uploads but if form.is_valid(): doesn't work and I don't
> know how to add it to the form data. how i can assign the downloaded
> image to my form (form.image=save)?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate