data = request.FILES.get('file')
from django.core.files.images import get_image_dimensions
from PIL import Image
im = Image.open(data) ---> No Quotes just pass the data here.
On Thu, May 10, 2018 at 7:31 PM, arvind yadav <
[email protected]> wrote:
> my views.py in admin.py file
>
> def changelist_view(self, request, extra_context=None,):
> extra_context = extra_context or {}
> if request.method == 'POST':
> #extra_context['form'] ='form'
> form = HomePageBannerForm(request.POST, request.FILES)
> if form.is_valid():
> data = request.FILES.get('file')
> from django.core.files.images import get_image_dimensions
> from PIL import Image
> im = Image.open('data')
> width, height = im.size
> print(width, height,'>>>>>>>') here i want size of image
> #form.save();
>
> else:
> form = HomePageBannerForm()
> extra_context['form'] = HomePageBannerForm()
> return super(HomePageBannerAdmin, self).render_change_form(request,
> extra_context)
>
>
>
> my form.html
>
>
> <form method="post" enctype="multipart/form-data">
> {% csrf_token %}
> {{ form.as_p }}
> <button type="submit">Upload</button>
> </form>
>
>
> facing this error on submit
>
> error section
>
>
>
>
> Internal Server Error: /homepage/homepagebanner/
> Traceback (most recent call last):
> File
> "/home/arvind/lib/python3.5/site-packages/django/core/handlers/exception.py",
> line 35, in inner
> response = get_response(request)
> File
> "/home/arvind/lib/python3.5/site-packages/django/core/handlers/base.py", line
> 128, in _get_response
> response = self.process_exception_by_middleware(e, request)
> File
> "/home/arvind/lib/python3.5/site-packages/django/core/handlers/base.py", line
> 126, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
> File
> "/home/arvind/lib/python3.5/site-packages/django/contrib/admin/options.py",
> line 574, in wrapper
> return self.admin_site.admin_view(view)(*args, **kwargs)
> File "/home/arvind//admin/main/admin.py", line 71, in inner
> safeview = view(request, *args, **kwargs)
> File "/home/arvind//admin/homepage/admin.py", line 72, in changelist_view
> im = Image.open('data')
> File "/home/arvind/lib/python3.5/site-packages/PIL/Image.py", line 2543, in
> open
> fp = builtins.open(filename, "rb")
> IsADirectoryError: [Errno 21] Is a directory: 'data'
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/b54d1197-7d4b-4a95-ac35-5e8f6284cfd1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b54d1197-7d4b-4a95-ac35-5e8f6284cfd1%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 [email protected].
To post to this group, send email to [email protected].
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/CAGGVXBNAuAbL4817tJ%2BV4d2Cd5xRnEnBaJGhjg--WpkXbwP%3DJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.