Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ckeditor is incompatible with ManifestStaticFilesStorage #192

Closed
SalahAdDin opened this issue May 25, 2015 · 34 comments
Closed

ckeditor is incompatible with ManifestStaticFilesStorage #192

SalahAdDin opened this issue May 25, 2015 · 34 comments

Comments

@SalahAdDin
Copy link

Hi guys, i have now an error with django-ckeditor 4.4.8 in my web server.

The webserver is webfaction, and my problem is the next:
I was using ckeditor in my page and work's fine, i have 4.4.7 and then updated for 4.4.8, i don't remember if i restarted the server but ckeditor works fine.
Then, i restarted the server and i try to used ckeditor but i couldn't see anything, see:
granproblemackeditor

I tried all things that i think, re collect static files, re put ckeditor urls in urls.py, all, but, nothing working.

But, in local server work fine, shure, doesn't used collecstatic, don't need it, but in the server doesn't works this.

Finally, i installed 4.4.7 and works again.
granproblema2

Compare the urls from the bugs in the before image and see here:
granproblema2

The source are correct loading in this case, correct url, but, with 4.4.8 the statics urls are wrong.

Then, i think that is the problem of 4.4.8 with static urls, but, i don't know why.

Can anyone fix it?

@riklaunim
Copy link
Contributor

Looks like no slash at the beginning of the path. The change made to URL generation of JS files was this one: 23b8a2e and it should work if your STATIC_URL is correctly set.

@SalahAdDin
Copy link
Author

No, the problem is that first part of url is wrong, news/new/.../static isn't correct, the correct ist static/static/...

@riklaunim
Copy link
Contributor

if the src is ="static/foo/bar.js" then it will be relative path which is wrong. if it would be "/static/foo/bar.js" then it should work correctly. What's the actual path in the raw HTML?

@SalahAdDin
Copy link
Author

I don't understand your question.
I saw that ckeditor put the urls as page's url childs, in this case, news/new/ckeditor...., and these isn't the correct url.

@riklaunim
Copy link
Contributor

Open the page source and check how they look. I have the latest version deployed in few places and all static files are working correctly. I assume you have something wrong with STATIC_URL - so check in the source, not in the rendered DOM what's the URL. and check/post what's your STATIC_URL.

@SalahAdDin
Copy link
Author

Wow, for now i can't do this, i fix the problem downgraded my django-ckeditor version, but tomorrow i try replicate this issue, thank you.

But for now, you can see the correct urls and compare with my first image.
granproblema3

Can you see?

@riklaunim
Copy link
Contributor

you can even do it without installing the new version. You can test the static() and STATIC_ROOT code example in manage.py/django-admin shell

@SalahAdDin
Copy link
Author

STATICFILES_DIRS = ('/home/salahaddinal/webapps/tiempoturco/tiempoturco/statics',)
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
STATIC_ROOT = '/home/salahaddinal/webapps/tiempoturco_static/static'
STATIC_URL = '/static/static/'

I have this.

@rafaelhdr
Copy link
Contributor

I had the same problem of the field no showing.
It worked when i added DefaultStorageFinder on settings.py
(i don't know why)

STATICFILES_FINDERS = (
     'django.contrib.staticfiles.finders.FileSystemFinder',
     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
-    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
+    'django.contrib.staticfiles.finders.DefaultStorageFinder',
 )

@riklaunim
Copy link
Contributor

If you have a custom storage then it's likely it will need its own finder too.

I'll also check if there isn't any CachedStaticFilesStorage regressions in the latest release.

@SalahAdDin
Copy link
Author

Ok, i will put the DefaultStorageFinder in my settings and try if works, thanks.

@SalahAdDin
Copy link
Author

Ok, don't work yet.
See please:
continua el problema
You can see my settings and the wrong urls.

@SalahAdDin
Copy link
Author

And now i have this issue:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/salahaddinal/webapps/tiempoturco/tiempoturco/docs/models.py", line 7, in <module>
    from ckeditor.fields import RichTextField
  File "/home/salahaddinal/lib/python3.4/ckeditor/fields.py", line 4, in <module>
    from ckeditor.widgets import CKEditorWidget
  File "/home/salahaddinal/lib/python3.4/ckeditor/widgets.py", line 51, in <module>
    class CKEditorWidget(forms.Textarea):
  File "/home/salahaddinal/lib/python3.4/ckeditor/widgets.py", line 56, in CKEditorWidget
    class Media:
  File "/home/salahaddinal/lib/python3.4/ckeditor/widgets.py", line 63, in Media
    static('ckeditor/ckeditor/ckeditor.js'),
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/contrib/staticfiles/templatetags/staticfiles.py", line 9, in static
    return staticfiles_storage.url(path)
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/contrib/staticfiles/storage.py", line 131, in url
    hashed_name = self.stored_name(clean_name)
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/contrib/staticfiles/storage.py", line 280, in stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/salahaddinal/webapps/tiempoturco/lib/python3.4/django/contrib/staticfiles/storage.py", line 94, in hashed_name
    (clean_name, self))

ValueError: The file 'ckeditor/ckeditor/ckeditor.js' could not be found with <django.contrib.staticfiles.storage.CachedStaticFilesStorage object at 0x7ff321c585c0>.

I delete all static files and try collect it again, and, see.

I searched and i find that this is a problem with CachedStorage... and is problem with the new url configuration, in 4.4.7 the urls in widgets were STATIC_URL+ but now is only static.

@riklaunim
Copy link
Contributor

I think you need slash on the end of STATIC_ROOT - https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-STATIC_ROOT

@SalahAdDin
Copy link
Author

Ok, i'll try with this.

@SalahAdDin
Copy link
Author

continua el problema

Don't works yet.

@alito
Copy link

alito commented Jun 7, 2015

I am seeing this too. It can only be seen if DEBUG is False otherwise static takes a shortcut.

Note that the ckeditor.js and ckeditor-init.js get found fine, it's config.js that is not found. This is because the 'static' call transforms the name to eg ckeditor.677756974519.js if you are using certain storages (ManifestStaticFilesStorage in my case), so if ckeditor is relying on its name to be ckeditor.js to find config.js, this will trip it up.

The quick solution for those that are hitting this is to revert 23b8a2e and go back to the STATIC_URL version. Longer term would be to modify ckeditor.js to be smarter in how it finds its dependencies

@riklaunim
Copy link
Contributor

So it's not as easy as it looked like.

@riklaunim
Copy link
Contributor

Reverted in master.

@SalahAdDin
Copy link
Author

it's seems very difficult but, will be better use static but search the way for fix this bug.
Thank you man.

@SalahAdDin
Copy link
Author

is there any update here?

@riklaunim
Copy link
Contributor

What update do you expect? At the moment no changes here. When I'll find some time I'll do some work on this package (there is a nice todo list).

@SalahAdDin
Copy link
Author

Oh yes, but, i was talking about the problem with change static_url gettin.

@riklaunim
Copy link
Contributor

It's hard to reproduce that config.js error with development server. Maybe circus/dj-static test setup could help test that.

@sebsheep
Copy link

It seems I have the same problem here. If debug = True, then all is ok, otherwise ckeditor.js, ckeditor-init.js are founded but not config.js (since the requested path by my browser is <current_path>/config.js instead of static/ckeditor/ckeditor/config.js).

I'm using the version 5.0.3 from pip, my relevant (I think) config vars are:

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' # just copy-pasted from Heroku dev center, I don't really understand what does it mean
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

Reading this thread, I feel this is the same problem as mine, but I didn't see any workaround for my issue.

@macolo
Copy link

macolo commented Jan 20, 2017

@SalahAdDin can you maybe rename this issue to something more descriptive?

I suggest ckeditor is incompatible with ManifestStaticFilesStorage?

For all the guys out there that run into the same issue and turn to Google for help...

@macolo
Copy link

macolo commented Jan 20, 2017

the changelog for 5.2.0 has a fix for ManifestStaticFilesStorage but I don't see this working (using 5.2.1).

https://github.com/django-ckeditor/django-ckeditor/blob/master/CHANGELOG.rst

5.2.0
-----
#. Django 1.10 updates
#. Development dependencies bump
#. CKEditor 4.6.1
#. Paste image support
#. Fix for ManifestStaticFilesStorage

@SalahAdDin SalahAdDin changed the title Problem with 4.4.8 in web server ckeditor is incompatible with ManifestStaticFilesStorage Jan 22, 2017
@Flimm
Copy link
Contributor

Flimm commented Apr 18, 2017

The fix in release 5.2.2 still doesn't work for me. See my comment in pull request #377 .

matthiask added a commit that referenced this issue Apr 23, 2017
@matthiask
Copy link
Member

This will be fixed in the next release. Please test the master branch (if you can) and report any problems in this issue tracker.

Thanks!

@Flimm
Copy link
Contributor

Flimm commented Apr 24, 2017

I just tried commit 2aaff4e and it still has problematic Javascript code that attempts to read an HTML attribute before the DOM element has been loaded yet.

However, I followed the instructions in the new documentation committed in e080a82, and that seemed to work for me!

@matthiask
Copy link
Member

Hmm, so you're saying that the code in ckeditor-init.js is running before the script tag with ID ckeditor-init-script (which references ckeditor-init.js!) is available to the DOM? That's really surprising! Do you have additional details about your environment that could help reproduce this?

@Flimm
Copy link
Contributor

Flimm commented Apr 24, 2017

@matthiask Ah, sorry, I just realised that I was actually testing 5.2.2. (For some reason, the deployment script I'm using didn't recognise a git+https:// dependency in requirements.txt.) I just tried out the new code on my development machine and it seems to work. Good work!

@matthiask
Copy link
Member

Great, thanks for testing!

@Tanishk-Sharma
Copy link

e080a82 has worked for me as well. Both in Development and in Production.
Production: heroku, gunicorn, whitenoise
using django-ckeditor==6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants