1đź‘Ť
If you use contrib.static, you have to execute a collectstatic
command to get all the app-specific static files (including admin’s own) into the public directory that is served by gunicorn.
1đź‘Ť
I’ve run into this problem too (because I do some development against gunicorn), and here’s how to remove the admin-media magic and serve admin media like any other media through urls.py:
import os
import django
...
admin_media_url = settings.ADMIN_MEDIA_PREFIX.lstrip('/') + '(?P<path>.*)$'
admin_media_path = os.path.join(django.__path__[0], 'contrib', 'admin', 'media')
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^' + admin_media_url , 'django.views.static.serve', {
'document_root': admin_media_path,
}, name='admin-media'),
...
)
Also: http://djangosnippets.org/snippets/2547/
And, of course, #include <production_disclaimer.h>
.
- [Django]-Django pass list to form to create Choices
- [Django]-Django CreateView filter foreign key in select field
- [Django]-Query on manyToMany field with related_name
1đź‘Ť
I think the easiest way is to add alias to nginx (are you using one?!) configuration file:
location /static/admin/ {
alias /<path_to_your_admin_static_files>/;
}
it worked immediately for me
0đź‘Ť
Ok, got it. Just had to add this line to settings.py
:
MEDIA_ROOT = '/home/claudiu/server/.virtualenv/lib/python2.5/site-packages/django/contrib/admin/media/'
- [Django]-Django – pass parameter from template to models.py' s function
- [Django]-Django Oscar change URL pattern
- [Django]-Drf-yasg/drf-spectacular – description for filter parameters
- [Django]-Django collectstatic on S3 uploads unchanged files everytime on Heroku
- [Django]-Django admin and column width through list_display
0đź‘Ť
David Wolever’s answer was close, for my installation, but I think some paths may have changed in newer django. In particular I set
admin_media_path = os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
and in urlpatterns added:
url(r'^static/admin/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': admin_media_path,
}),
based on info found here: https://docs.djangoproject.com/en/dev/howto/static-files/
works for me, but more “magical” than I like.
- [Django]-Django ManyToMany field is not created in model
- [Django]-What is the difference between SlugField() vs CharField() in Django models