Reputation: 32232
Like the title says, everything 404s with:
Page not found (404)
Request Method: GET
Request URL: http://localhost/static/admin/css/base.css
Using the URLconf defined in djcms.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, static/admin/css/base.css, didn't match any of these.
Basically I'm just following the tutorial on DjangoProject.com, so there's nothing much complicated going on here aside from Django itself.
My folder structure looks like:
root@jerkstore:/var/www/djcms# ls -lsa
total 36
4 drwxrwxr-x 6 myusername myusername 4096 Jul 11 11:49 .
4 drwxr-xr-x 10 myusername www-data 4096 Jul 10 16:34 ..
4 drwxrwxr-x 5 myusername myusername 4096 Jul 11 11:40 admin
4 drwxrwxr-x 2 myusername myusername 4096 Jul 11 15:38 djcms
4 -rwxr-xr-x 1 myusername myusername 248 Jul 10 16:34 manage.py
4 drwxrwxr-x 2 myusername myusername 4096 Jul 11 10:53 polls
4 -rw-rw-r-- 1 myusername myusername 415 Jul 11 10:26 .project
4 -rw-rw-r-- 1 myusername myusername 577 Jul 11 10:26 .pydevproject
4 drwxrwxr-x 2 myusername myusername 4096 Jul 11 11:43 static
root@jerkstore:/var/www/djcms# ls -lsa static/
total 12
4 drwxrwxr-x 2 myusername myusername 4096 Jul 11 11:43 .
4 drwxrwxr-x 6 myusername myusername 4096 Jul 11 11:49 ..
4 lrwxrwxrwx 1 myusername myusername 73 Jul 11 11:43 admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/
root@jerkstore:/var/www/djcms# ls -lsa static/admin/
total 20
4 drwxr-sr-x 5 root staff 4096 Jul 10 16:33 .
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 ..
4 drwxr-sr-x 2 root staff 4096 Jul 10 16:33 css
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 img
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 js
Note: FollowSymLinks is enabled in Apache
And the relevant sections of settings.py look like:
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = '/var/www/djcms/static'
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
#'/var/www/djcms/static',
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
ADMIN_MEDIA_PREFIX = '/static/admin/'
I've tried several different permutations of the STATIC_ vars in settings.py, but nothing's worked so far, and neither has anything else I've been able to Google up.
Upvotes: 2
Views: 6445
Reputation: 137290
It looks like the request for admin
app's static file is hitting Django app. I assume your URLs are defined properly, but it is worth rechecking with Django static files configuration.
As seen in the documentation on static files:
Serving the files
In addition to these configuration steps, you’ll also need to actually serve the static files.
During development, this will be done automatically if you use
runserver
andDEBUG
is set toTrue
(seedjango.contrib.staticfiles.views.serve()
).This method is grossly inefficient and probably insecure, so it is unsuitable for production.
See Deploying static files for proper strategies to serve static files in production environments.
It means, that you need to setup your web server (eg. Apache) to serve static files outside Django (so the request to this URL should not even reach Django app).
Also make sure you have invoked collectstatic
.
Upvotes: 9