how to access uploaded file list in django forms.py
Hello friends how can i access uploaded file list (multi file upload) in forms.py ? In a view i access file list like this : *request.FILES.getlist('files')* but in forms.py i get this error: *Exception Value:'UploadForm' object has no attribute 'request'* i tried to add request object to my form , but i get error when using this code : *def clean_files(self):data = self.request.FILES* this is the error: *Exception Value:'NoneType' object has no attribute 'FILES'* i want it for form validation *any help is really appreciated* -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACq8ZqDOvLNYSDqNLski_dMUfLYQD%3Dp7qjkE%2BHb94FmUZfX-DQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
is it possible to manipulate image in PIL after uploading directly by its "request.FILES.GETLIST(FORMFIELD)" address not the saved picture on hard disk
Hello Friends is it possible to manipulate image in PIL after uploading directly by its " *request.FILES.GETLIST(FORMFIELD)*" address not the saved picture on hard disk? I wrote a function for manipulating but its only working with " *Image.open('a.jpg')* " but i don't want to save image after uploading and then opening it for manipulating , is it possible to manipulate image with its "request.FILES" object address? -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9b6734c8-4530-42b3-b791-99bbce020b32%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
problem in converting PIL image object to django file object for saving in imagefield model type
Hi everybody I wanted to save PIL image object in model ImageField , but before doing that i have to convert PIL image object to django file-like object I found a solution with stringIO but the problem is that in this solution " io_object.len" is used and "len" is not available in pythin3 here is the link to solution: http://stackoverflow.com/questions/3723220/how-do-you-convert-a-pil-image-to-a-django-file So how can i convert PIL image object to django file-like object for saving in model type ImageField best regard -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a4685c6c-f136-4d5f-8230-edb08fb30c36%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: is it possible to manipulate image in PIL after uploading directly by its "request.FILES.GETLIST(FORMFIELD)" address not the saved picture on hard disk
thanks for answering with your help solved the problem if any one get to this problem, here is how i solved it: filelist = request.FILES.getlist('uploadimage') #first get list of your uploaded file object as list for imgfile in filelist: # iterate over your list and give each uploaded photo object to your PIL img = Image.open(imgfile) # you can open your uploaded photo object as normal picture like this #your manipulation and changes on picture comes here img.save('MypicName.jpeg') #finaly save your picture like this On Friday, August 26, 2016 at 8:35:21 PM UTC+4:30, Asad Jibran Ahmed wrote: > > Hi, > Every object in `request.FILES` is actually a file *liike* object that > you can use for processing. I guess you can use something like > `PIL.Image.frombytes` with the `request.FILES[filename].read()` data. > > Django Doc for the `request.FILES`: > https://docs.djangoproject.com/en/1.10/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile > Pillow (PIL Fork) documentation for the `frombytes` method: > https://pillow.readthedocs.io/en/3.3.x/reference/Image.html#PIL.Image.frombytes > > Hope that helps. > Regards, > > Asad Jibran Ahmed > > http://blog.asadjb.com > > On Fri, Aug 26, 2016 at 7:46 PM, ali Eblice > wrote: > >> Hello Friends >> is it possible to manipulate image in PIL after uploading directly by its >> "*request.FILES.GETLIST(FORMFIELD)*" address not the saved picture on >> hard disk? >> >> I wrote a function for manipulating but its only working with " >> *Image.open('a.jpg')* " but i don't want to save image after uploading >> and then opening it for manipulating , is it possible to manipulate image >> with its "request.FILES" object address? >> >> -- >> 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...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/9b6734c8-4530-42b3-b791-99bbce020b32%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/9b6734c8-4530-42b3-b791-99bbce020b32%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0323b1af-6ada-4daa-9d47-f9eba95a8b43%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: problem in converting PIL image object to django file object for saving in imagefield model type
Thanks for answering problem solved by seeking here is how i didi it in case of any one needed it: img = Image.open('test.png') #first we open an image with PIL or maybe you have it from uploaded file already(you should import PIL and Image) img_io = io.BytesIO()#creat in memory object by io (you should import io) img.save(img_io,format='png') #save your PIL image object to memory object you created by io #you should import InMemoryUploadedFile thumb = InMemoryUploadedFile(img2_io, None, 'foo2.jpeg', 'image/jpeg',thumb_io.seek(0,os.SEEK_END), None) #give your file to InMemoryUploadedFile to create django imagefield object #take look at this link to find out to import what things: https://groups.google.com/d/msgid/django-users/a4685c6c-f136-4d5f-8230-edb08fb30c36%40googlegroups.com On Saturday, September 10, 2016 at 6:04:18 PM UTC+4:30, ludovic coues wrote: > > Using seek should do the trick. > It's a function, taking an offset as its first value and a flag as > second value indicating from where to apply the offset. It return the > position after the seek operation. So io_object.seek(0, os.SEEK_END) > will tell you the number of characters in io_object. That should be > equal to the size. > > 2016-09-10 9:49 GMT+02:00 ali Eblice >: > > Hi everybody > > I wanted to save PIL image object in model ImageField , but before doing > > that i have to convert PIL image object to django file-like object > > I found a solution with stringIO but the problem is that in this > solution > > "io_object.len" is used and "len" is not available in pythin3 > > here is the link to solution: > > > http://stackoverflow.com/questions/3723220/how-do-you-convert-a-pil-image-to-a-django-file > > > > > So how can i convert PIL image object to django file-like object for > saving > > in model type ImageField > > best regard > > > > -- > > 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...@googlegroups.com . > > To post to this group, send email to django...@googlegroups.com > . > > Visit this group at https://groups.google.com/group/django-users. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/django-users/a4685c6c-f136-4d5f-8230-edb08fb30c36%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > Cordialement, Coues Ludovic > +336 148 743 42 > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4b98c8af-4376-4cb0-8ac2-a31b38a7fc0f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Import css in Django
your "mysite" folder and "static" folder are in a same directory but in your settings.py you wrote "STATIC_ROOT='/mysite/static/'" which says that static should be subdirectory of mysite which its not a subdirectory its in a same directory of mysite On Sunday, September 11, 2016 at 8:48:57 PM UTC+4:30, Jonathan Cheng wrote: > > > https://gist.github.com/cj10243/fb557903441d4a3e95190b854fbaabe1 > > ludovic coues於 2016年9月12日星期一 UTC+8上午12時05分12秒寫道: >> >> I have a hard time to read the paths you use. The command tree produce >> a nice tree view of a directory, it might help. You can also use >> service like http://paste2.org/ or https://gist.github.com/ to share >> it >> >> 2016-09-11 17:58 GMT+02:00 Jonathan Cheng : >> > thx reply,but it just can see the original html with no css,is my path >> > setted correct? >> > >> > ludovic coues於 2016年9月11日星期日 UTC+8下午11時45分24秒寫道: >> >> >> >> Have you tried to add a few newlines to be sure about which line is >> the >> >> issue ? >> >> >> >> Also, in you email, there is a space between % and } in the load >> >> staticfiles tag >> >> >> >> 2016-09-11 7:29 GMT+02:00 Jonathan Cheng : >> >> > I use django1.10 >> >> > >> >> > i reference the official doc >> >> > https://docs.djangoproject.com/en/1.10/intro/tutorial06/ >> >> > >> >> > my project name:mysite >> >> > >> >> > structure: >> >> > >> >> > - mysite- >> >> > >> >> > - mysite - urls.py >> >> > >> >> >-views.py >> >> > >> >> > ... >> >> > >> >> > - templates - index.html >> >> > >> >> > - images >> >> > - static - mysite - assets - css - main.css >> >> > >> >> > - js >> >> > >> >> > ... >> >> > In my index.html >> >> > >> >> > add >> >> > >> >> > `{% load staticfiles % } >> >> > ` >> >> > >> >> > it said i have a Invalid block tag about TemplateSyntaxError >> >> > `` >> >> > >> >> > views.py (about static files part) >> >> > ```STATICFILES_DIRS = [ >> >> > os.path.join(BASE_DIR, "static"), >> >> > '/mysite/static/', >> >> > ] >> >> > STATIC_URL = '/static/' >> >> > STATIC_ROOT='/mysite/static/'``` >> >> > >> >> > what's part should i notice? >> >> > >> >> > -- >> >> > 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...@googlegroups.com. >> >> > To post to this group, send email to django...@googlegroups.com. >> >> > Visit this group at https://groups.google.com/group/django-users. >> >> > To view this discussion on the web visit >> >> > >> >> > >> https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com. >> >> >> >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> >> >> >> >> -- >> >> >> >> Cordialement, Coues Ludovic >> >> +336 148 743 42 >> > >> > -- >> > 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...@googlegroups.com. >> > To post to this group, send email to django...@googlegroups.com. >> > Visit this group at https://groups.google.com/group/django-users. >> > To view this discussion on the web visit >> > >> https://groups.google.com/d/msgid/django-users/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com. >> >> >> > >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> >> Cordialement, Coues Ludovic >> +336 148 743 42 >> > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c24cc8e8-39f9-47ac-afb0-394eaf1f724c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
question about returning file (pdf,image,zip...) in a request that made from temporary URL
hello think of a downloading website: when we create a temporary link in django and map it to actual URL or file path in database like this: id -- temporary_URL -- origin_URL -- file_path so when a user used a temporary URL and directed to some view , how should i return that file from that view for user to be able to download that file? i know that i can use "FileResponse" or "StreamingHttpResponse" but in django documentation says that we should use these for short-lived requests but downloading a big file can take long time, so what should i do ? i appreciate any help and idea -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/691d2358-77c7-49b3-bfe1-9b54c29262ea%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: question about returning file (pdf,image,zip...) in a request that made from temporary URL
thanks for reply i setup the x-sendfile but there's a problem : django return a x-sendfile response successfully but since i'm using django development area and the development area runs on port 8000 the return response will be on port 8000 but the apache web server runs on port 80 so the response wont go to apache so it cause me to download the file with 0 byte size how can i solve this problem ? On Friday, October 28, 2016 at 6:29:53 PM UTC+3:30, ali Eblice wrote: > > hello > think of a downloading website: > when we create a temporary link in django and map it to actual URL or file > path in database like this: > > id -- temporary_URL -- origin_URL -- file_path > > so when a user used a temporary URL and directed to some view , how should > i return that file from that view for user to be able to download that file? > i know that i can use "FileResponse" or "StreamingHttpResponse" but in > django documentation says that we should use these for short-lived requests > but downloading a big file can take long time, so what should i do ? > i appreciate any help and idea > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9d0fc69a-ca82-4b2f-81ce-82ba58afdf92%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.