Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin static files only -> 404

I have a django project that works fine with the embedded server, but when I try to use it on Apache/mod_wsgi, the static files of the admin pages (/static/admin/css) are not found (404). Here are my settings:

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = '/var/www/wsgi/myproject/static'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'

STATICFILES_DIRS = ()

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )


TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    )

TEMPLATE_CONTEXT_PROCESSORS = (
    "socialauth.context_processors.facebook_api_key",
    'django.core.context_processors.media',
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.request",
    "django.core.context_processors.static",
    )

ROOT_URLCONF = 'myproject.urls'

TEMPLATE_DIRS = ('/var/www/wsgi/myproject/templates',)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'myproject.myapp',
    )

I also tried running

sudo python ./manage.py collectstatic

but with no luck.

like image 729
user967722 Avatar asked Aug 28 '26 02:08

user967722


1 Answers

What does you apache virtualhost config look like? You should include an Alias directive for the STATIC_ROOT path.

Something along these lines:

Alias /static [project-path]/static
Alias /media [project-path]/media
<Directory [project-path]/static>
    Order deny,allow
    Allow from all
</Directory>
<Directory [project-path]/media>
    Order deny,allow
    Allow from all
</Directory>

As you've written, you would need to run ./manage collectstatic each time you want to deploy new static files in production.

like image 57
Bouke Avatar answered Aug 29 '26 15:08

Bouke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!