Forums

Why is Ckeditor not working?

installed apps:

INSTALLED_APPS=[
    'ckeditor',             # for variety of options while writing blog
    'ckeditor_uploader,
]

models.py

from ckeditor_uploader.fields import RichTextUploadingField

class Post(models.Model):
    ...
   content = RichTextUploadingField()

My post_form.html contains these script to enable ckeditor in frontend

<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
 <script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>

My admin site is also not responding to ckeditor too. Localhost supports it but not here.

P.S. Staffs are welcome to look into codes and all if you need.

Edit: after seeing the error log I found this:

 Not Found: /static/ckeditor/ckeditor-init.js
 Not Found: /static/ckeditor/ckeditor/ckeditor.js

there weren't any js files anyways when I ran in localhost but why now?

Update again : I changed the path of ckeditor-init.js and ckeditor.js to where it is i.e to my virtual env

      <script type="text/javascript" src="/home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-package/ckeditor/static/ckeditor/ckeditor-init.js"></script>
      <script type="text/javascript" src="/home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static/ckeditor/ckeditor/ckeditor.js"></script>

and added url path in WEB App Setup as

/static/.................../home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static/ckeditor/ckeditor-init.js      
/static/.................../home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static/ckeditor/ckeditor/ckeditor.js

It is still giving me the error:

   Not Found: /home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static/ckeditor/ckeditor-init.js
    Not Found: /home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static/ckeditor/ckeditor/ckeditor.js

Can anyone tell me what's going on?

Take a look at https://help.pythonanywhere.com/pages/DjangoStaticFiles/ and https://help.pythonanywhere.com/pages/DebuggingStaticFiles/

I did went there but couldn't find my way around the problem exactly.

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'blog/static'),]
STATIC_ROOT = 'home/drizzleofthoughts/drizzleofthoughts/blog/static'

I have these in settings.py and also I have

/static/admin/ in **WEB APP setup**

with the url path to

/home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/django/contrib/admin/static/admin/

to load up the css to admin page. Is the problem with my STATIC_URL and STATIC_ROOT?

Hi, uhm is anyone here? I'm in stress. Can't figure this thing out, unfortunately. I'll be so grateful if you can sort this one out for me. Please

You probably don't want to have the URL path for the static file mapping to where you have it. It should be to your STATIC_ROOT, which needs a slash at the start and make sure that you have run collectstatic.

You probably don't want to have the URL path for the static file mapping to where you have it.

What does that mean? Am I supposed to make changes to STATIC_URL? To what?

It should be to your STATIC_ROOT, which needs a slash at the start

Oh yes I did it a while ago after I posted this. And I did run collectstatic but:

SystemCheckError: System check identified some issues:
ERRORS: 
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.

I got this error. Do I just remove STATICFILES_DIRS?

Okay coders here's an update. I really hope these will be helpful for all of you in the future.

So, after a quick lookup to docs (cough stackoverflow cough ) I found out STATIC_URLS copies data from STATICFILES_DIRS; so what I did was completely opposite. Now here's an update

STATIC_URL = '/static/'

STATICFILES_DIRS = [os.path.join(BASE_DIR, '/home/drizzleofthoughts/.virtualenvs/venv/lib/python3.10/site-packages/ckeditor/static'),]
STATIC_ROOT = '/home/drizzleofthoughts/drizzleofthoughts/blog/static'

And the CKEDITOR script I ran in post_detail.html, I changed it to how it was earlier. i.e:

<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
 <script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>

This was so simple to solve yet I scratched my head quite literally for a whole day.

How does your static files mapping look like on the "Web" page on PythonAnywhere?