You are not logged in.
Note: these instructions are old and outdated. Please refer to our Django documentation for the recommended method of serving your admin media.
Here is a short guide explaining how to serve your Django admin media files directly from the machine's main Apache server (without going through your Apache2/mod_python instance). This is a good idea because it is faster and since you should limit the number of your Apache2/mod_python processes you won't be using any of these processes to serve static files.
- Create a new app from the control panel. Call it "admin_media" for instance. Under "App type", choose "Symbolic link". Under "Extra info", enter the path to your admin media file (<home dir>/lib/python2.4/django/contrib/admin/media). This will create a file $HOME/webapps/admin_media which is a symbolic link to <home dir>/lib/python2.4/django/contrib/admin/media.
- Edit your website record and mount your "admin_media" app on "/media". Apache will get reconfigured within a few minutes and it will handle the "admin_media" app as a normal static/cgi/php app.
Remi.
Offline
Thank you!!
Offline
If you want to mesh with django authentication, see:
<http://www.djangoproject.com/documentation/apache_auth/>
(I haven't tried it yet, but I'm about to. :)
Last edited by shaunc (2006-10-15 05:16:29)
Offline
By the by, Could you explain (or offer a link) to a newb such as myself what exactly a 'Symbolic Link' is? What would be the difference between doing what you suggested and setting up a static application to serve the files out of /media?
Thanks!
Offline
landslideinc wrote:
By the by, Could you explain (or offer a link) to a newb such as myself what exactly a 'Symbolic Link' is?
You can think of symbolic links as shortcuts in the Linux world.
landslideinc wrote:
What would be the difference between doing what you suggested and setting up a static application to serve the files out of /media?
As things currently stand, to serve a Django application there are two instances of Apache doing the dirty work. One is server wide, everyone on the server uses it. The other is located in the same directory as your Django project and serves your Django application. However, the instance that serves your Django application isn't being accessed directly, it's proxied to from the server wide instance. This allows you to restart your Django application without affecting everyone else on the same server, as you'd only be restarting the instance that serves your Django application. With that said, in this set up using a symbolic link allows the server wide Apache instance to serve the admin media, which is faster because you would be cutting out the middle man, the instance that serves your Django application. It's recommended that you use one server to serve your Django application and another to serve your media, not just the admin media, which could be done in a similar fashion.
Hopefully that made sense. ![]()
Edit: This also applies to Mongrel and Rails, the only difference is that you'd set up a symbolic link to the public directory.
Last edited by IAIHMB (2006-10-20 19:40:47)
Offline
BTW, I forgot to mention it but this technique also works for any static data, not just the admin media, and it also works for other tools, not just Django.
Remi.
Offline
So if I have a Django project using some_path/template/project which contains directories like /images /javascript and /style:
some_path/template/project/images
some_path/template/project/javascript
some_path/template/project/style
Do I have to create applications to handle each subdirectory. Or do I just point the symbolic link at some_path/template/project ?
Not sure how all the mapping occurs in Apache?
Thanks,
-Paul
Offline
You got it right the second time, symlinks handle subdirectories. ![]()
Offline
IAIHMB wrote:
You got it right the second time, symlinks handle subdirectories.
What about when you're doing this with Rails? The public directory in rails is the root of the web app, and it's served from / by the rails app with mongrel. When you create a symbolic link app pointing to the public directory, you can't also set it up to serve /, but that's where you need it to serve since all the static files are in there.
Offline
You would have to fake it by pointing the directories in (Rails Application Directory)/public/ to subdirectories, for example:
-(Rails Application Directory)/public/images/ would point to /images/.
If you don't have that many applications left you could move the media to a subdirectory or subdomain.
Offline
Ok.. I just did this and the control panel said there was an error and the team was notified. Apart from that, a question: What is the url of the static files now?
Forgive me if the answer should somehow be obvious.. I am new.
Thanks
Robert
Offline
Just in case someone else runs into a similar problem if you want an application to be available at a URL you must add it to one of your sites.
Hope it helps. ![]()
Offline
It's worth nothing that you'll need to add the following to your httpd.conf or else Django's instance of Apache will intercept all requests to /admin_media/:
<Location "/admin_media">
SetHandler default
</Location>Hope it helps. ![]()
Offline
I'm a little confused. I've setup my 'symbolic link' app using the name 'admin_media' and putting 'home2/spyderfcs/lib/python2.4/django/contrib/admin/media' in the extra info area. I then went to 'websites' in the control panel and added the 'admin_media' app with a url path of /admin_media
I see the link when I am on my FTP client but I can't for the life of me get the django admin to load the media files. I have http://mysiteurl.com/admin_media/ set in the settings.py file for the admin media but nothing. I've tried a bunch of different stuff there but I'm obviously jut missing something. Also, I added the above to the httpd.conf in my apache2/conf/ folder.
I'm obviously a noob when it comes to all the server side stuff so any help would be much appreciated.
Thanks in advance!
Offline
You forgot the forward slash in the beginning, it should have been:
/home2/spyderfcs/lib/python2.4/django/contrib/admin/media
I've made the change for you and now it's working as expected.
Hope it helps. ![]()
Offline
IAIHMB wrote:
You forgot the forward slash in the beginning, it should have been:
/home2/spyderfcs/lib/python2.4/django/contrib/admin/media
I've made the change for you and now it's working as expected.
Hope it helps.
Der....long day.....Thanks a ton!!
Offline
I'm a little confused; I don't understand the difference between the two app types. Why would I want to use a "Symlink" app instead of a "Static" app to serve my static content (images, stylesheets, etc.)?
My view so far is that they are exactly the same thing, except the Static app creates a new folder, and Symlink has to point at an existing one.
Offline
That's pretty much it.
Sometimes people would like to have their static content in a directory other than ~/webapps/(Application Name)/ and in this situation it didn't make sense to move it.
Offline
Do I need to use the application control panel or can I simply set default handlers for all my static content and alias the directories in my Apache conf?
For example:
<Location "/media">
SetHandler none
</Location>
<Location "/img">
SetHandler None
</Location>
<Location "/css">
SetHandler None
</Location>
<Location "/js">
SetHandler None
</Location>
<Location "/plugin">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png|js|css|html|txt|php)$">
SetHandler None
</LocationMatch>
Alias /media /home2/pkenjora/lib/python2.4/django/contrib/admin/media
Alias /img /home2/pkenjora/webapps/django/arkayne/templates/images
Alias /css /home2/pkenjora/webapps/django/arkayne/templates/css
Alias /js /home2/pkenjora/webapps/django/arkayne/templates/js
Alias /plugin /home2/pkenjora/webapps/django/arkayne/templates/plugin
Offline
You can do that if you'd like but it's not recommended. For the reasons that Remi mentioned earlier it's better to go about things the way Remi mentioned earlier. Using Remi's method should also minimize your memory usage.
Hope it helps. ![]()
Offline
Remi wrote:
Edit your website record and mount your "admin_media" app on "/media".
Could someone post an example/walkthrough of this, please? I thought I understood all the words in that sentence, but since my solution did not net me any nifty css on my admin, apparently I thought wrong. Thanks!
Offline
markguy,
First off, I apologize for the delay. You created the application of type symlink but you didn't add it to your website. I've done it for you and now everything is working as expected. You can see what I did at "Domains/Websites -> Websites" in the control panel.
Hope it helps. ![]()
Offline
Err, thanks! By the way, the lawn's getting a little long, should you still be so motivated ![]()
Offline
I'm afraid I need a little more hand holding, though I think I'm almost there. I have a very small Django site and when I visit one of my links I get a 413 error (request entity too large). The link points to a very simple page, so I'm not asking the server to serve huge files or anything.
So I've been following this thread to serve my admin files from the main Apache server, thinking that would reduce the load. In the control panel, I go to >Home>Sites and see two apps for my subdomain:
/: django and /media: admin_media.
The admin_media is the soft link described above.
In my settings.py file I have:
MEDIA_ROOT = '/home/donnes/webapps/django/media/' MEDIA_URL = 'http://donnes.webfactional.com/media/' ADMIN_MEDIA_PREFIX = '/media/'
In my httpd.conf I have:
# limit file uploads to 10 Mb
LimitRequestBody 10240000
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE donnes.settings
PythonPath "['/home/donnes/webapps/django'] + sys.path"
PythonDebug On
</Location>
<Location "/admin_media">
SetHandler default
</Location>
<Location "/media/files">
SetHandler none
</Location>
<LocationMatch "\.(jpg|gif|png)$">
SetHandler None
</LocationMatch>With this setup my admin page is seeing the css files correctly. The "/media/files" is screwed up but I'll attack that later. The 413 error comes up when I visit a login page, which in the urls.py is:
(r'^login/$', login), # where login is django.contrib.auth.views.login
There's nothing special about this login page, except that I'm using my own template.
Can anyone see where I'm going wrong?
Last edited by drsanchez (2007-08-25 20:53:14)
Offline
drsanchez wrote:
I'm afraid I need a little more hand holding, though I think I'm almost there. I have a very small Django site and when I visit one of my links I get a 413 error (request entity too large). The link points to a very simple page, so I'm not asking the server to serve huge files or anything.
So I've been following this thread to serve my admin files from the main Apache server, thinking that would reduce the load. In the control panel, I go to >Home>Sites and see two apps for my subdomain:Code:
/: django and /media: admin_media.The admin_media is the soft link described above.
In my settings.py file I have:Code:
MEDIA_ROOT = '/home/donnes/webapps/django/media/' MEDIA_URL = 'http://donnes.webfactional.com/media/' ADMIN_MEDIA_PREFIX = '/media/'In my httpd.conf I have:
Code:
# limit file uploads to 10 Mb LimitRequestBody 10240000 <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE donnes.settings PythonPath "['/home/donnes/webapps/django'] + sys.path" PythonDebug On </Location> <Location "/admin_media"> SetHandler default </Location> <Location "/media/files"> SetHandler none </Location> <LocationMatch "\.(jpg|gif|png)$"> SetHandler None </LocationMatch>With this setup my admin page is seeing the css files correctly. The "/media/files" is screwed up but I'll attack that later. The 413 error comes up when I visit a login page, which in the urls.py is:
(r'^login/$', login), # where login is django.contrib.auth.views.login
There's nothing special about this login page, except that I'm using my own template.
Can anyone see where I'm going wrong?
It's hard to tell without looking at your setup. Can you tell us what your WebFaction username is or open a ticket in the support system ?
Also, can you give us one particular URL that doesn't work ?
Cheers,
Remi.
Offline