Forums

admin css not working

How do you get admin css working for django?

We've recently made that work automatically when you create a new Django app, but I think your web app was set up before we did that. So:

  • If you haven't configured your web app yet and don't mind creating a fresh one, just delete it and then create a new one. The Django admin should have the css all sorted already.
  • If you want to keep the existing one, then add the following mappings to the "Static files" table for the app:

.

URL                Directory
/static/admin/     /usr/local/lib/python2.7/site-packages/django/contrib/admin/media
/static/           /home/MOC/mysite/static
/media/            /home/MOC/mysite/media

I love easy solutions!

Us too!

YES The entire PA platform is about making easy solutions for the rest of us...Well, and you too since you do eat your own dog food...☺

(to PA crew) What magic exactly are you guys doing in the background when we add those mappings for Static Files? Before I see this forum post, I was trying to use sym link to connect "myproject/static/" with "usr/local/lib/python2.7/site-packages/django/contrib/admin/media". It would be nice to know in case I run into similar static file mapping stuff in the future. If this question sound idiotic (I'm new to Django), please ignore. Thanks :)

There are no idiotic questions :-)

The magic we're doing is that our web server intercepts requests for URLs specified by static files before they're handed to your web app. However, it's quite likely that we're not letting the system follow symlinks (I can check when I'm in the office on Monday) for security reasons. So if you saw problems with that, that might be the reason.

Thanks for your explanation, giles. :) From little of what I've tested, it seems like setting up symlinks in my app folder to access "/usr/local/lib/..../django/contrib/admin" isn't working. This is a question out of curiosity and maybe for future PA users who are learning Django as a beginner as I am. :)

Makes sense. A lot of web servers don't follow symlinks by default, and it looks like we're left that in place.

Hello! May I ask for help with the same problem too? My admin isn't rendering with the right CSS either (although the public app is fine). I've tried the above-mentioned and variants of it as well as this custom fix (https://www.pythonanywhere.com/forums/topic/67/) but didn't exactly get to the celebration step.

Well it's functional, but I guess it would be nice to get it to render properly. Any direction you could point me in would be much appreciated!

The problem is that the admin UI is looking for its CSS at /static/admin/ and you don't have that set up anywhere. Normally our Django quickstart wizard sets one up for you, but if it's no longer there you can create it in the static file mapping table with the URL stub /static/admin/ and the directory /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media

Oh wow, that simple? It's fixed now, thank you!

I had created the project not as a Django project but followed the manual configuration method for importing a project developed on my localhost, I guess that's why the admin static wasn't set up for me.

I think this didn't work for me before when I was trying out the first suggestion in this thread. Okay but it works now anyway. Alright sweet. Thanks again!

No problem, glad to help!

Hi, with my app this doesn't work

/static/admin/ /usr/local/lib/python2.7/site-packages/django/contrib/admin/media

I have to do this

/static/admin /home/YOURNAME/.virtualenvs/blog/lib/python2.7/site-packages/django/contrib/admin/static

@barrachi - yes, if you're using a virtualenv, you have to point at the virtualenv version of django...

Yes, there is always python manage.py collectstatic if you want all static files in one dir.