13๐
In addition to correcting the symbolic link as Daniel Roseman suggested, youโll need to make sure that the user that is running Apache has read access to the admin media.
- If you do
ls -l
in your media directory, do you see the symbolic link? - If you
cd admin
from your media directory, does it work? If you then runls
can you see the admin media? - Does the user that runs Apache have read access to the admin media?
If all those things work, then please update your question with your current configuration and results of those commands and weโll take another look.
Response to Update: Ok, the permissions look ok. It looks like youโve got the directory structure in your media directory a little bit wrong.
The fact that /usr/lib/python2.6/site-packages/django/contrib/admin/media/
was empty is disturbing, too. Once you solve the immediate problem you may want to look into reinstall django in the expected place.
Anyways, hereโs how the structure should look:
$ cd media
$ ls -la
drwxr-xr-x 2 root root 4096 Apr 13 03:33 .
drwxr-xr-x 3 root root 4096 Apr 8 09:02 ..
lrwxrwxrwx 1 root root 60 Apr 13 03:33 admin -> /usr/lib/python2.6/site-packages/django/contrib/admin/media/
-rw-r--r-- 1 root root 9 Apr 8 09:02 test.txt
That is, inside of the media/
directory their should be a link called admin
directly to the /admin/media
directory of your django installation.
To fix what youโve got, inside of the media/admin/
directory run:
rm media
cd ..
rmdir admin
and then re-create the symlink as suggested in Daniel Rosemanโs answer.
7๐
Thereโs a couple of problems here, both to do with your symbolic link.
Firstly, the source and target needed to be the other way round (I always get that wrong myself).
Secondly, you have used a completely different path to the one youโve specified in your Apache conf โ djangotest/sgelections
vs django/sgel
.
Do it like this:
cd /home/django/sgel/media/
ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media/ admin
- [Django]-Does Django queryset values_list return a list object?
- [Django]-Django staticfiles not found on Heroku (with whitenoise)
- [Django]-How do I start up remote debugging with PyCharm?
6๐
The easy solution is to change a line in your wsgi.py file
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
becomes
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
Easiest way to have the Admin CSS show properly. Cheers
- [Django]-Django โ how to visualize signals and save overrides?
- [Django]-'dict' object has no attribute 'id'
- [Django]-Trying to migrate in Django 1.9 โ strange SQL error "django.db.utils.OperationalError: near ")": syntax error"
5๐
Another method I just found, and it looks like a properly supported method.
Make sure you have the staticfiles module in your settings. Also configure the STATIC_ROOT option.
https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#module-django.contrib.staticfiles
Create your /static/ folder and set permissions.
Configure apache with a /static/ alias.
alias /static <path to project root>/static/
<Directory "<path to project root>/static/">
Order deny,allow
Allow from all
</Directory>
then from your project folder run
sudo python manage.py collectstatic [-n to do a dry run]
All this looks like it does is copy the admin static files to your projects folder for web serving.
- [Django]-Django Admin โ save_model method โ How to detect if a field has changed?
- [Django]-How can I disable Django's admin in a deployed project, but keep it for local development?
- [Django]-Django data migration when changing a field to ManyToMany
3๐
So the first thing you want to do is change directory to your static folder and add a symlink.
I did this with a virtual environment so I use
ln -s ~/virtualenv/my-virtualenv/lib/python2.x/site-packages/django/contrib/admin/static/admin admin
The next step is to edit your httpd.conf
Alias /static/admin/ ~/mysite/static/admin/
Restart your apache server and voila!
- [Django]-Django: guidelines for speeding up template rendering performance
- [Django]-How to output Django queryset as JSON?
- [Django]-How to reset Django admin password?
2๐
In Firebug, use the Net tab and see the requests being made by your browser for the css files. see the response for your requests there itself. I think you will find the problem there.
I recently had the same problem. The problem was when my browser requests for the css files, the response contained the contents of my projectโs login html page. I donโt remember now that how i solved my problem. I will try to recollect and post the solution here.
Let me know if you have the same problem.
- [Django]-Django how to see sql query when running tests?
- [Django]-Django custom view into admin page
- [Django]-Django migrations using RunPython to commit changes
2๐
I had the same problem but none of this helped really. Turned out my version of grappelli was outdated. (https://github.com/sehmaschine/django-grappelli) I uninstalled it and then re-installed with a newer version.
pip install django-grappelli==2.4.4
If you are using an admin skin like me, you might consider updating it.
- [Django]-Get the index of an element in a queryset
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-Coverage.py warning: No data was collected. (no-data-collected)
1๐
can you run
python
>>> import django
>>> print django.__file__
the other question โ does your normal media placed into the /home/django/sgel/media/ work (i.e. served by Apache as expected?)
- [Django]-Django Rest Framework ImageField
- [Django]-Requirements.txt greater than equal to and then less than?
- [Django]-Django 1.8 migrate is not creating tables
1๐
Try to add
Options FollowSymLinks
to your
<Directory /home/django/sgel/media>
Order deny,allow
Allow from all
</Directory>
so that you end up with
<Directory /home/django/sgel/media>
Options FollowSymLinks
Order deny,allow
Allow from all
</Directory>
- [Django]-Is there a HAML implementation for use with Python and Django
- [Django]-Multiple ModelAdmins/views for same model in Django admin
- [Django]-Django ignores router when running tests?
1๐
Iโm not sure if this will help but in my config file I have:
Alias /adminmedia/ /var/lib/python-support/python2.6/django/contrib/admin/media/
<Directory "/var/lib/python-support/python2.6/django/contrib/admin/media">
AllowOverride None
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
It works but I have my server set up for development/testing only.
- [Django]-Django viewset has not attribute 'get_extra_actions'
- [Django]-CORS error while consuming calling REST API with React
- [Django]-Django IntegerField with Choice Options (how to create 0-10 integer options)
1๐
i used to have the same problem, i solved it by using the FireFox plugin firebug, which tells you where is your site looking for the media files, also how did you check the contents of the admin/media folder to see if they were empty ?
- [Django]-"Too many values to unpack" Exception
- [Django]-Django templates: forloop.first and forloop.last
- [Django]-Django return redirect() with parameters
1๐
I know itโs been solved but I think itโs worthy to share my solution.
I simply added the alias in apache and it worked so far.
Alias /static/admin/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/
Alias admin/media/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/
- [Django]-Django ignores router when running tests?
- [Django]-Django project models.py versus app models.py
- [Django]-How to add verbose_name to forms
0๐
Did you try setting the value for
MEDIA_ROOT
MEDIA_URL
ADMIN_MEDIA_PREFIX
correctly?
I mean that the MEDIA_ROOT url and ADMIN_MEDIA_PREFX should have a different value. Please check these values in your settings.py and try again.
Hope this helps.
- [Django]-How to get a favicon to show up in my django app?
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
- [Django]-Django date to javascript at the template
0๐
I encountered the same problem while running the Bitnami Django Stack on Win32 (builtin development server)
I solved the issue by finding the missing CSS folders in the installation and changing settings.py.
# Additional locations of static files
STATICFILES_DIRS = (
'C:/Program Files/BitNami DjangoStack/apps/django/django/contrib',
)
This will help you get started developingโฆ Itโs not optimal. Donโt forget the trailing comma ๐
- [Django]-How to use async function based views in DRF?
- [Django]-Django model with 2 foreign keys from the same table
- [Django]-Django CSRF check failing with an Ajax POST request
0๐
If nothing helps, add the following to urls.py
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { <br/>
'document_root': '/usr/lib/python2.4/site-packages/django/contrib/admin/media/', <br/>
'show_indexes' : True, <br/>
}), <br/>
This is independent of apache or nginx
- [Django]-Django search fields in multiple models
- [Django]-Serializing a list of objects with django-rest-framework
- [Django]-Overriding initial value in ModelForm
0๐
when we talked about django, we should know which edition we run on. โADMIN_MEDIA_PREFIXโ is used in django before edition of 1.4, see
The included administration app django.contrib.admin has for a long time
shipped with a default set of static files such as JavaScript, images and
stylesheets. Django 1.3 added a new contrib app django.contrib.staticfiles
to handle such files in a generic way and defined conventions for static
files included in apps.
Starting in Django 1.4, the admin's static files also follow this convention,
to make the files easier to deploy. In previous versions of Django, it was
also common to define an ADMIN_MEDIA_PREFIX setting to point to the URL where
the admin's static files live on a Web server. This setting has now been deprecated
and replaced by the more general setting STATIC_URL. Django will now expect to
find the admin static files under the URL <STATIC_URL>/admin/.
https://docs.djangoproject.com/en/dev/releases/1.4/.
I am using django 1.4, and still confusing about this.
- [Django]-How to get an app name using python in django
- [Django]-Django + PostgreSQL: How to reset primary key?
- [Django]-Django: Using an F expression for a text field in an update call
0๐
If youโre using virtualenvwrapper
like me, then this is how you can find your admin media files and fix it:
workon <project_name>
export DJANGO_BASEFILE=`python -c 'import django; print django.__file__'`
export DJANGO_BASEDIR=$(dirname ${DJANGO_BASEFILE})
ln -s $DJANGO_BASEDIR/contrib/admin/media <project_dir>/media/admin
Replace the <project_name>
to your virtualenvwrapper environment name and project_dir
to your working directory. ๐
- [Django]-Django-object-permissions Vs django-guardian Vs django-authority
- [Django]-How do I display current time using Python + Django?
- [Django]-AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
0๐
In my case, this issue occured after setting up the nginx on Ubuntu server. On analyzing the file structure, I found that admin folder was missing from the staticfile directory (the location where django looks for static files to add to STATIC_ROOT
). So, I copied the admin folder (inside static directory) to the serverโs static folder.
Then run
python manage.py collectstatic
And now, django collects the 130 files required for admin page styling.
- [Django]-How to define two fields "unique" as couple
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
- [Django]-Detect django testing mode
0๐
I want to add to Adamโs Solution,
first you need to install dj-static in cpanel. So add dj-static==0.0.6 in requirements.txt then install
dj-static==0.0.6
and then edit the project wsgi.py file:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
then restart the cpanel. Hope Admin will have a Proper Look. Thanks
- [Django]-DatabaseError: current transaction is aborted, commands ignored until end of transaction block?
- [Django]-Simple search in Django
- [Django]-Django REST Framework (DRF): TypeError: register() got an unexpected keyword argument 'base_name'
0๐
a simple answer for this problem is moving admin and static folder to public_html
I had this problem and it worked
try it
- [Django]-Django delete superuser
- [Django]-How to find pg_config path
- [Django]-When should I use escape and safe in Django's template system?
-1๐
I am Ansh Sharma. I also faced this same issue, and it was just too scary. Here I have something which can solve the problem. Go to Your setting file and make
DEBUG = TRUE
I hope this solves your issue
Happy Coding.
Ansh Sharma
- [Django]-Return nested serializer in serializer method field
- [Django]-Django Celery โ Cannot connect to amqp://guest@127.0.0.8000:5672//
- [Django]-Import error 'force_text' from 'django.utils.encoding'