How can I specify where ckeditor.js is located? - django

I'm trying to integrate django-ckeditor into my admin forms. I've followed the required documentation but whenever I want to add a new blog post through my CMS the following error occurs:
[01/Aug/2013 14:21:34] "GET /admin/RehabLog/post/add/ HTTP/1.1" 200 8608
[01/Aug/2013 14:21:34] "GET /admin/RehabLog/post/add/static/static/ckeditor/ckeditor/ckeditor.js HTTP/1.1" 301 0
[01/Aug/2013 14:21:34] "GET /admin/jsi18n/ HTTP/1.1" 200 5169
[01/Aug/2013 14:21:34] "GET /admin/RehabLog/post/add/static/static/ckeditor/ckeditor/ckeditor.js/ HTTP/1.1" 404 1800
Now ckeditor.js isn't there which leads me to two questions: Where is ckeditor.js and how can I tell django where it is?
As requested here are my some settings:
MEDIA_URL = '//s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = '/%s/' % DEFAULT_S3_PATH
STATIC_ROOT = os.path.join(basepath, 'staticfiles')
STATIC_URL = 'static/'

You may need to set CKEDITOR_BASEPATH variable in order to have the library working correctly.

You must have a directory in your application that serves staticfiles. That is where you should put the ckeditor.js. Normally the folder is in root of project and is called static
It has to be the same folder referred to in the settings file as STATIC_ROOT or listed in STATICFILES_DIRS. This way you'll just add {{STATIC_ROOT}}ckeditor.js to the template to have it served in the html

Related

Using a readymade Template for django frontend

I tried using a readymade HTML5 template for my Django Project and updated the static links and all but it fails to load the CSS and js and other static files too.
My folder structure :
**MyProject
apps
templates
MyProject
static
MyProject
css
js
etc**
My Settings for static :
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
TEMPLATES = [
......
'DIRS': [os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR,'static') .
..... ]
I have tried
using the collectstatic command.
Adding STATICFILES_DIRS.
Adding this code snippet to urls.py
Trace from terminal:
[04/Apr/2020 13:04:51] "GET /static/css/owl.theme.default.min.css HTTP/1.1" 404 1814
[04/Apr/2020 13:04:51] "GET /static/css/animate.css HTTP/1.1" 404 1772
[04/Apr/2020 13:04:51] "GET /static/css/magnific-popup.css HTTP/1.1" 404 1793
[04/Apr/2020 13:04:51] "GET /static/css/aos.css HTTP/1.1" 404 1760
[04/Apr/2020 13:04:51] "GET /static/css/owl.carousel.min.css HTTP/1.1" 404 1799
collectstatic will collect static resources that you have placed in your individual apps and copy them to an app directory within the project static directory. So, if you have an app static directory like this:
my_app
static
my_app
css
js
etc
your project static dir will look like this after collectstatic:
static
my_app
css
js
etc
You can also manually place static resources in the project static directory. This is a good place for your project wide css, js, and image files.
static
css
images
js
From the 404 errors you posted, the server is looking for your css files in the static/css/ directory and you have your css directory inside the MyProject directory. Move your css directory out one level and place your css files there and it should work.
static
MyProject
css
js
Your Error:
"GET /static/css/owl.theme.default.min.css HTTP/1.1" 404 1814
according to your error server is looking your file in static folder and then in css while your files is in static/MyProject/css
so, update your code in your html file
{% static 'MyProject/css/owl.theme.default.min.css' %}

Some static files in django serve 404 when other dont- any ideas why?

Using django 1.5
I got static files configured like this:
STATIC_ROOT = '/home/<user>/Projects/<name>/static'
STATIC_URL = '/static/'
i just run manage.py collectstatic
directory listing:
static/css
static/css/bootstrap.css
static/css/addressbook.css
static/css/bootstrap-responsive.css
static/css/rewrite.css
static/css/login.css
when I type
localhost:8000/static/css/addressbook.css i got 404
but:
localhost:8000/static/css/bootstrap.css
gives me a proper css content
WTF? they are in the same folder and have same user/rights/groups
part from menage.py runserver output:
[24/Jul/2013 12:18:19] "GET /static/css/addressbook.css HTTP/1.1" 404 1663
[24/Jul/2013 12:19:16] "GET /static/css/login.css HTTP/1.1" 200 533
[24/Jul/2013 12:20:12] "GET /static/css/addressbook.css HTTP/1.1" 404 1663
[24/Jul/2013 12:32:51] "GET /static/css/bootstrap.css HTTP/1.1" 304 0
UPDATE:
It's serving files not from "project/static" but from static folder under application folder
I figure that out by deleting static forder under one app - files start to give 404. Same if I disable AppDirectoriesFinder.
But it still not consistent some applications don't serve files even from "static" under application folder.
My ideal situation will be: AppDirectoriesFinder commented out and all files served from myProject/static/
You can't just drop files into the /static folder of your project. Django doesn't "see" files in that directory unless they were collected from the apps via collectstatic. You will get a 404 trying to access files that you drop in there manually.
You need to put static files into the /static directory of an app (if it doesn't belong in a specific app, just create a new one, for example "main" or "website").
Alternatively you can set the STATICFILES_DIRS for Django to search additional directories when you call collectstatic.
I had the same problem. Here's my solution:
Add this to your settings.py
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
#"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

Django-debug-toolbar not displaying (Can't find the .js and .css) and display is at "none" [duplicate]

I'm trying to get django-debug-toolbar to work, and after following all the instructions, I'm getting these errors:
[05/Sep/2012 15:33:35] "GET /profile/edit/ HTTP/1.1" 200 43647
[05/Sep/2012 15:33:36] "GET /profile/edit/debug_toolbar/css/toolbar.min.css HTTP/1.1" 404 86163
[05/Sep/2012 15:33:36] "GET /profile/edit/debug_toolbar/css/toolbar.min.js HTTP/1.1" 404 66260
The HTML source is calling these things relative.
When I grep through the debug-toolbar sources, I see these two lines line:
debug_toolbar/templates/debug_toolbar/base.html:5:<link rel="stylesheet" href="{{ STATIC_URL }}debug_toolbar/css/toolbar.min.css" type="text/css">
debug_toolbar/templates/debug_toolbar/base.html:6:<script type="text/javascript" src="{{ STATIC_URL }}debug_toolbar/css/toolbar.min.js"></script>
However, my STATIC_URL is set to /static/ in the settings.py file for the project. Did I misconfigure something here?
I manually applied bugfixes provided here and it did a trick for me.

How do I serve static admin files in Django 1.4?

I have a Django project that was started with Django 1.2. Now I'm trying to run it under Django 1.4, in a development environment, using the built-in webserver. One thing I cannot get working is the static files for the admin interface. In my django server's window, I see:
Django version 1.4, using settings 'settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[18/Jul/2012 11:38:04] "GET /admin/ HTTP/1.1" 200 6452
[18/Jul/2012 11:38:05] "GET /admin/admin/css/base.css HTTP/1.1" 404 4249
[18/Jul/2012 11:38:05] "GET /admin/admin/css/dashboard.css HTTP/1.1" 404 4264
I see that ADMIN_MEDIA_PREFIX has been deprecated, but I'm clearly missing the HOWTO that tells me what I have to do to get the admin pages working in development.
Have you tried running collectstatic to gather your static files?
https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic
I finally started another project with "django-admin startproject", and started picking through the settings file. I found that the new settings file had:
added 'django.contrib.staticfiles' to INSTALLED_APPS
added a few STATIC_ settings. I copied these four:
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = ()
And now things appear to be working.
In django 1.4 you can use the static tag
{% load static %}
<a href="{% static 'img/foo.png' %}">

Django admin media not loading

I'm trying to deploy this application with nginx/gunicorn but I don't know why the admin media files are missing.
settings.py:
ADMIN_MEDIA_PREFIX = '/srv/www/antingprojects.com.ar/gobras/static/admin/'
I also tried:
ADMIN_MEDIA_PREFIX = '/static/admin/'
project folder:
/srv/www/antingprojects.com.ar/gobras/static/admin/css|js|img
urls.py:
(r'^static/admin/(?P<path>.*)$', 'django.views.static.serve')
nginx access.log:
"GET /admin/ HTTP/1.1" 200 1556 "-"
"GET /srv/www/antingprojects.com.ar/gobras/static/admin/css/base.css HTTP/1.1" 404 1136 "http://antingprojects.com.ar/admin/"
"GET /srv/www/antingprojects.com.ar/gobras/static/admin/css/dashboard.css HTTP/1.1" 404 1141 "http://antingprojects.com.ar/admin/"
"GET /admin_media/img/admin/nav-bg.gif HTTP/1.1" 404 1114
You need to set up a symbolic link from the directory where the admin media files are to the static media directory you are using to serve your static files.
The admin media files should be at something like:
path/to/django/contrib/admin/media/
Once your symlink is set up you would set your ADMIN_MEDIA_PREFIX to the symbolic directory within the directory where you serve your static files, so something like this should work:
ADMIN_MEDIA_PREFIX = '/static/admin/'
Check to see where your admin is trying to load its media files from, and this should help you get started if you can't figure out which directory to use.
Here's a quick tutorial on symlinks:
http://ubuntuforums.org/showthread.php?t=255573
Your ADMIN_MEDIA_PREFIX is correct, you just need to remove /admin portion from your static view URL, because what you have now specified translates to a URI beginning with /static/admin/admin for accessing your admin resources through the static view.
Thank you for your help, the problem was in the nginx.conf, I wasn't locating /static folder.
location /static {
root /srv/www/antingprojects.com.ar/gobras;
}