jonasundderwolf / django-image-cropping

Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.
Other
553 stars 130 forks source link

django-image-cropping not working with django 3.2.8 #172

Closed AttilioGreco closed 2 years ago

AttilioGreco commented 2 years ago

Hi i'm having same issue using django-image-cropping. Admin is not showing copping box, with django-image-cropping==1.5.0 is working without problem

js console show this error

jQuery.Deferred exception: jQuery is not a function @http://127.0.0.1:8000/static/image_cropping/js/dist/image_cropping.min.js:1:17764
mightThrow@http://127.0.0.1:8000/static/admin/js/vendor/jquery/jquery.js:3762:29
resolve/</process<@http://127.0.0.1:8000/static/admin/js/vendor/jquery/jquery.js:3830:12
 undefined
 Uncaught TypeError: jQuery is not a function
    <anonymous> http://127.0.0.1:8000/static/image_cropping/js/dist/image_cropping.min.js:1
    jQuery 13
        mightThrow
        process
        setTimeout handler*resolve/<
        fire
        fireWith
        fire
        fire
        fireWith
        ready
        completed
        EventListener.handleEvent*
        <anonymous>
        <anonymous>

Regars

pmyjavec commented 2 years ago

Maybe a compatibility issue with jQuery versions? I did the following and it solved my issue.

IMAGE_CROPPING_JQUERY_URL = "https://code.jquery.com/jquery-3.6.0.min.js"
agsimmons commented 2 years ago

I've looked more into this and it isn't related to the Django version. This happens on 2.2.x and 3.2.

This issue appears due to 68ec5af . In 1bd36d2 , the variable is added back but with a blank value.

I'm unclear on the intended installation of v1.6.0 or higher. The README still states

By default the image cropping widget embeds a recent version of jQuery.

but this doesn't appear to be true anymore.

@pmyjavec 's solution does resolve the issue, but that requires the user of the library to specify their own jQuery URL by default. If this is the intention, then this should be documented in the README and it also should probably cause raise a Python error if this value is not specified.

Maybe using the jQuery version vendored with the Django admin would be a good default? I was able to use the jQuery version built in to the admin app by using

IMAGE_CROPPING_JQUERY_URL = STATIC_URL + "admin/js/vendor/jquery/jquery.min.js"

It works fine with Django 2.2.26 and 3.2.11

anrie commented 2 years ago

@agsimmons You are right, the README wasn't up to date. And thanks for tracking the issue down!

We made a new release and followed your idea to use Django's bundled jQuery as default JQUERY_URL.

@AttilioGreco Can you confirm that the widgets work again if you use the latest version? (1.6.2)

AttilioGreco commented 2 years ago

I have try a fast upgrade in a separated Brach Now is Working with

django-image-cropping-1.6.2
Django-3.2.11

But is conflicting with tabbed admin solved with

IMAGE_CROPPING_JQUERY_URL = None