Newbie question, I'm having difficulty getting the admin panel to work!

11 views
Skip to first unread message

Rishi

unread,
Jun 23, 2011, 4:25:16 PM6/23/11
to Django users
Hi everyone,
I've just started using Django, and everything has been smooth sailing
up until this part. I added 'django.contrib.admin' in settings.py for
installed apps, and changed urls.py to allow for the admin page to
work. However, the admin page works erratically. That is, at some
points no matter whether I'm at my root project page or at the admin
page, I'll always see that light blue django launch page. At other
times, I get the admin login page to work, but NEVER with any styles
associated with it. It's always just html plaintext. What's going on,
and how do I fix it?

A few specifics about my setup. I'm running django completely remotely
(mediatemple (ve) server), and am using cyberduck/vim concurrently to
edit the files on the server. I'm working on a mac on my side, and I
have doublechecked each configuration file to make sure everything is
saved correctly. I've also installed phpmyadmin and have checked the
database to make sure that's set up correctly. To the best of my
knowledge it is.

Thanks for any and all help!

Eiji Kobayashi

unread,
Jun 23, 2011, 7:35:25 PM6/23/11
to django...@googlegroups.com
Hello,

I'm not exactly sure about your other problems, but the problem with not getting any styles seem to me like you didn't set your ADMIN_MEDIA_PREFIX correctly in your settings file and/or your web server configuration file. You must let it know how to access all the javascript, css and image files to display your admin pages correctly.

I'm not sure what type web server mediatemple uses, but I am using nginx (under Debian stable) and I had to put this in my server configuration file:

server {
...
location ^~ /static/admin/ {
  alias /usr/lib/python2.5/sites-packages/django/contrib/admin/media/;
}
location ^~ /static/ {
  root /var/www;
}
...

For apache, I believe an equivalent setting would be something like this in your virtualhost file:
...
Alias /static/admin/ "/usr/lib/python2.5/sites-packages/django/contrib/admin/media"
...

And in the settings.py file of my project, I set the following:
...
STATIC_URL = '/var/www/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'

This tells Django to issue the '/static/admin/' prefix whenever it needs something to display the admin pages, and then the webserver will follow up by retrieving them from the correct place (/path/to/python/site-packages/django/contrib/admin/media).

I hope this works. Good luck!

Eiji

P.S. What erratic behaviors are you seeing? Please explain more.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Rishi

unread,
Jun 24, 2011, 10:11:48 AM6/24/11
to django...@googlegroups.com
Thanks for trying to help me out, Eiji.
I tried adding the Alias in the apache configuration file and changing settings.py, but to no avail. I still get the same error. What happens, specifically, is that when I go to the django project page, everything seems to work, I get the same light blue launch screen that I am supposed to get. When I go to /admin/, however, I get one of two pages. 
1. The same launch page (this is the more common result),
2. If I am lucky, I see the admin page, but with no styles associated with it. As soon as I refresh this page, it goes back to the same light blue launch page.

I'm going through the tutorial on the Django official website, but I don't see any instructions pertaining to STATIC_URL in settings.py. Am I perhaps reading something wrong?

Thanks again,
Rishi

Eiji Kobayashi

unread,
Jun 24, 2011, 8:48:51 PM6/24/11
to django...@googlegroups.com
Hi Rishi,

STATIC_ROOT, STATIC_URL, etc. are somewhat new additions to Django. I have troubles with the documentation myself because the new ones describing them are in English :). But I think everything that they considered static - javascript, css, img, and other media were to be inside a directory tree defined by the MEDIA* variable.

Recently, they separated that into both MEDIA and STATIC variables. I may be wrong, but I think now they encourage MEDIA to be things like user-uploaded files, such as music, video, etc. files, and STATIC now should point to js, css, and img.

I have seen documentations referring to usage of STATIC variables, but I read two paragraphs and fall asleep :)

As for the alias directive not working. Can you try issuing:


You should see a css file on your browser. If you get an error, it means that the web server is not able to find the file, which is required to render the admin pages correctly (along with the required js, and img directories as well).

Even though you type:


to get to your admin panel. The subsequent pages will (through the definitions I suggested above in the settings file) try to locate the necessary js,css,img files using the '/static/admin/' prefix.

Good luck!

Eiji

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/2Qrt67V_5o8J.

Nan

unread,
Jun 24, 2011, 9:11:56 PM6/24/11
to Django users

The sporadicness may have to do with the way it's being served -- that
happens to me when running via FCGI if I save a change but don't
restart the process. Depending on your server setup, that may mean
touching the WSGI file or touching another special file or restarting
your Apache process or something else.

Eiji Kobayashi

unread,
Jun 24, 2011, 11:13:47 PM6/24/11
to django...@googlegroups.com
Ah, yes.

You may be right. It may be a simple problem with a simple answer. Maybe I just over complicated things with too much words and explanation.

Eiji

--
You received this message because you are subscribed to the Google Groups "Django users" group.

Rishi

unread,
Jun 24, 2011, 11:16:47 PM6/24/11
to django...@googlegroups.com
Thanks guys, I'll try this and get back to you!


Rishi
Reply all
Reply to author
Forward
0 new messages