40๐
Django recommends that you deploy static files with a web server other than wsgi.
- In settings.py, set:
STATIC_ROOT = 'static'
-
Run
python manage.py collectstatic
, which will copy the Django admin static files to/path/to/project/static/
-
Configure your static file server. If you use Nginx, you could add this config:
location /static/ { alias /path/to/project/static/; expires modified +1w; }
-
Reload your web server
You should now have access to the static files.
28๐
In Django 1.4 ADMIN_MEDIA_PREFIX
is deprecated. Here are the steps I followed to catch up with these somewhat recent Django changes:
-
in
settings.py
, adddjango.contrib.staticfiles
toINSTALLED_APPS
-
in
settings.py
defineSTATIC_URL
โ the staticfiles app wonโt run without it. While usingrunserver
theyโll get handled magically, but when you deploy, this needs to be a location where those resources can be fetched by a browser.
I think thatโs all there was to it.
- [Django]-Get current user in Model Serializer
- [Django]-Programmatically saving image to Django ImageField
- [Django]-Django FileField upload is not working for me
19๐
Iโm using Django 1.4.3
What did NOT work for me:
No matter how much I edited ADMIN_MEDIA_PREFIX in settings.py I noticed no change in the HTML generated for the Django Admin pages. It always says /media/admin/base.css when I view the source.
What DID work for me.
Copied the โadminโ folder from /django/contrib/admin/static/
and pasted it into my projects โmediaโ folder
Now it works great.
- [Django]-Django REST Framework POST nested objects
- [Django]-Good ways to sort a queryset? โ Django
- [Django]-Calling Django `reverse` in client-side Javascript
13๐
It seems dumb, but I actually had this exact issue and the solution was to set DEBUG=False
to DEBUG=True
on my local dev environment. When debug is set to False, it thinks itโs in a production environment which relies on a place to put static files, such as /var/www/html/static
, whereas the debug set to True just uses the local directory.
- [Django]-How to convert JSON data into a Python object?
- [Django]-How to render .rst files in a markdown or html format?
- [Django]-Add additional options to Django form select widget
5๐
Also make sure that AppDirectoriesFinder is not commented, happens when youโre trying to customize your own app structure. Unfortunatelly itโs pointless to seek such information in official docs.
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
- [Django]-Django {% with %} tags within {% if %} {% else %} tags?
- [Django]-How to go from django image field to PIL image and back?
- [Django]-Python vs C#/.NET โ what are the key differences to consider for using one to develop a large web application?
3๐
just change one thing in settings.py
DEBUG = False # not working if you are not serve your static files for production.
just change
DEBUG = True
- [Django]-CSV new-line character seen in unquoted field error
- [Django]-How do I perform HTML decoding/encoding using Python/Django?
- [Django]-ImportError: bad magic number in 'time': b'\x03\xf3\r\n' in Django
2๐
You need a trailing slash in your ADMIN_MEDIA_PREFIX
setting.
Change to:
ADMIN_MEDIA_PREFIX = '/static/admin/'
- [Django]-ImproperlyConfigured: The included urlconf <project>.urls doesn't have any patterns in it
- [Django]-Django: Safely Remove Old Migrations?
- [Django]-How to iterate through dictionary in a dictionary in django template?
1๐
in my project, the solution is in settings.py
, set:
DEBUG = False # debug false mod not working css
- [Django]-How to set a value of a variable inside a template code?
- [Django]-Django error: render_to_response() got an unexpected keyword argument 'context_instance'
- [Django]-H14 error in heroku โ "no web processes running"
0๐
Iโm using chef to auto-build my django server on an AWS Ubuntu server. This post helped, but what I wound up doing was to add the directory to the package admin static pages in a local_setings.py:
https://github.com/jaycrossler/geoq-chef-repo/blob/master/cookbooks/geoq/templates/default/local_settings.py.erb#L16
(added to local_settings.py or to settings.py):
STATICFILES_DIRS = ('<%= node['geoq']['virtualenv']['location'] %>/local/lib/python2.7/site-packages/django/contrib/admin/static/',)
This resulted in local_settings.py having:
STATICFILES_DIRS = ('/var/lib/geoq/local/lib/python2.7/site-packages/django/contrib/admin/static/',)
Note, that if you have other items already in your STATICFILES_DIRS, you might want to append to the list, rather than overwriting it.
- [Django]-Django how to pass custom variables to context to use in custom admin template?
- [Django]-Negating a boolean in Django template
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
0๐
One solution might be to add your local IP to the ALLOWED_HOSTS
list in settings.py
e.g.
CURRENT_IP = '192.168.0.123'
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '0.0.0.0', CURRENT_IP]
- [Django]-Django index page best/most common practice
- [Django]-Django test RequestFactory vs Client
- [Django]-Django โ Reverse for '' not found. '' is not a valid view function or pattern name
0๐
you need
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
- [Django]-Is there a function for generating settings.SECRET_KEY in django?
- [Django]-Python/Django: how to assert that unit test result contains a certain string?
- [Django]-Multiple images per Model
0๐
I donโt know how it was resolved, but I took these steps when I encountered the same problem. I simply add these line in settings.py.
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder','compressor.finders.CompressorFinder', )
i hope this will help you all.
- [Django]-Accessing "Media" files in Django
- [Django]-Django: Assigning variables in template
- [Django]-Multiple ModelAdmins/views for same model in Django admin
-3๐
In settings.py
Donโt use tuple for the
STATICFILES_DIRS =(
os.path.join(BASE_DIR, โstaticโ),
)
you should use list,like this
STATICFILES_DIRS =[
os.path.join(BASE_DIR, โstaticโ),
]
- [Django]-Django Imagefield not working properly via ModelForm
- [Django]-How to POST a django form with AJAX & jQuery
- [Django]-Generating a Random Hex Color in Python