0

I have found a few questhons re my problem, you the solutions didn't help me so I started a new question. Basically that's how I see the admin page no css/no js/ no images

Apache's config:

<VirtualHost *.*.*.*:80>
    ServerName ********.org
    ServerAdmin ****@******.org

    WSGIScriptAlias / /var/www/webproxy/webproxy/wsgi.py

    DocumentRoot /var/www/cgi-bin/
    ScriptAlias /cgi-bin/ /var/www/cgi-bin/

    ErrorLog /var/www/webproxy/apache/error.log

LogLevel warn

CustomLog /var/www/webproxy/apache/access.log combined

Alias /media/ "/var/www/webproxy/media/"

<Directory "/var/www/webproxy/media/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

<Directory "/var/www/webproxy/static/">
    Order deny,allow
    Allow from all
</Directory>

This is what I have in urls.py:

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

from core import urls as core_urls

from settings import MEDIA_ROOT, WEBPROXY_MEDIA_ROOT

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}),
    (r'^ui/(?P<path>.*)$', 'django.views.static.serve', {'document_root': WEBPROXY_MEDIA_ROOT}),
)

settings.py:

MEDIA_ROOT = '/var/www/webproxy/media/'
STATIC_ROOT = '/var/www/webproxy/static/'
WEBPROXY_MEDIA_ROOT = '/var/www/webproxy/static/media/'

I'm not sure what's wrong here. Any help would be really appreciated.

3
  • Your settings.py values for MEDIA_ROOT and WEBPROXY_MEDIA_ROOT? Commented Dec 3, 2012 at 16:50
  • Are the Django admin media files copied (ideally symbolically linked) under any of the above static files locations? Edited my answer. Commented Dec 3, 2012 at 16:59
  • yes, all of them (symlinked) :). I trying to solve the issue, so currently all of those static folreds have 'admin' folder with all files I need, but they're still not displaying Commented Dec 3, 2012 at 17:13

1 Answer 1

2

First, you shouldn't be serving the static files via django.views.static.serve in production as that is meant to be used only for local development (read docs here):

There may be files other than your project's static assets that, for convenience, you'd like to have Django serve for you in local development.

Second, your Django Admin static files reside under the location Django was installed at. I find using directly these files a better solution than copying (or symlink'ing) the Django admin static files under my own static files directories.

Example Django static files location on my server:

/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;

Therefore in your web server config you have to point the url /media/admin to

[my_django_location]/contrib/admin/static/admin/

If you're doing things locally, then you might need another entry in your urls.py:

(r'^admin/static/(?P<path>.*)$', 'django.views.static.serve', '/path/to/your/admin/files/'),
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for your first advise, I will follow it when I move this app to production mode. Re second, i have created a symbollical link ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media/ admin to all static folders. This didn't help :(
@KennyPowers Try to access an individual css file from the browser; might be something wrong with the structure of your files on disk rather than Django static file routing.
Page not found (404) Request Method: GET Request URL: http://****.org/static/admin/css/base.css that's what I got...
@KennyPowers Updated my answer - see last part.
@KennyPowers You have to set Apache/Nginx to serve static files from a specific location where the server has access. I.e. it must be something with your server config.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.