Serving media files

25 views
Skip to first unread message

Jagdeep Singh Malhi

unread,
Jun 17, 2010, 7:17:15 AM6/17/10
to Django users
i am using this link
http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#howto-deployment-modwsgi

In this link i am unable to under stand topic SERVING MEDIA FILES
the lines(given below) which is used in this tutorial , i am able
understand where we edit this line , if its edit in apache/
httpd.conf .so its ok

but I am also not found this """/usr/local/wsgi/static/media/"""
this path in my file system ,
and where i place "/media" directory which have""css,js,img"
directory which is used in admin

{

Alias /robots.txt /usr/local/wsgi/static/robots.txt
Alias /favicon.ico /usr/local/wsgi/static/favicon.ico

AliasMatch /([^/]*\.css) /usr/local/wsgi/static/styles/$1

Alias /media/ /usr/local/wsgi/static/media/

<Directory /usr/local/wsgi/static>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi

<Directory /usr/local/wsgi/scripts>
Order allow,deny
Allow from all
</Directory>
}

i am used ubuntu10.04 with apache server

and my my project is place in directory "/home/your_name/mysite/'



Graham Dumpleton

unread,
Jun 17, 2010, 8:03:55 AM6/17/10
to Django users


On Jun 17, 9:17 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> i am using this linkhttp://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#howto-...
All the directories are examples only, you would change them to be
what is appropriate for your system.

In the case of the media files you would copy them from the contrib/
admin/media directory under where Django is installed to some place
where your site is.

Thus, run Python and go:

>>> import django
>>> import os
>>> os.path.dirname(django.__file__)
'/lib/python2.6/site-packages/django'

Copy the directory called 'contrib/admin/media' from under that
directory and put that with your site. Then set up the Alias to refer
to it.

You could set the Alias to refer to the directory in the installed
Django installation if you want and not copy it, but copying it will
allow you to modify the media files and not muck up your original
Django installation.

Graham


Jagdeep Singh Malhi

unread,
Jun 17, 2010, 1:53:54 PM6/17/10
to Django users
Sir Graham
my actual problem is this :-

Myhttp://localhost/admin/ is display in pattern without grapic or
image not like that which is shown in Tutorial
http://docs.djangoproject.com/en/1.2/intro/tutorial02/#intro-tutorial02

MY admin page (http://localhost/admin/)

Django administration
Welcome, Jagdeep. Change password / Log out
Site administration
Auth
Groups Add Change
Users Add Change
Polls
Polls Add Change
Sites
Sites Add Change

Recent Actions
My Actions

where is the problem .........i am not able to find???



On Jun 17, 5:03 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

Graham Dumpleton

unread,
Jun 17, 2010, 7:55:10 PM6/17/10
to Django users


On Jun 18, 3:53 am, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> Sir Graham
> my actual problem is this :-
>
>  Myhttp://localhost/admin/is display in  pattern without grapic or
> image not  like that which is shown in Tutorialhttp://docs.djangoproject.com/en/1.2/intro/tutorial02/#intro-tutorial02
>
>  MY admin page (http://localhost/admin/)
>
>  Django administration
>  Welcome, Jagdeep. Change password / Log out
>  Site administration
>    Auth
>  Groups  Add     Change
>  Users   Add     Change
>     Polls
>  Polls   Add     Change
>     Sites
>  Sites   Add     Change
>
>  Recent Actions
>  My Actions
>
>  where is the problem .........i am not able to find???

Your problem is that you seem not to have done what I told you to. You
will get that because you aren't serving Django media files for css
etc via Apache. My email told you where to find the files. You need to
use Alias directives as documented to map to that directory or copy
media files into project area and map to that directory instead.

Graham

Jagdeep Singh Malhi

unread,
Jun 19, 2010, 1:18:57 AM6/19/10
to Django users

On Jun 17, 5:03 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

i copy the media directory in my "/home/yourname/mysite"
directory.
>
> Thus, run Python and go:
>
> >>> import django
> >>> import os
> >>> os.path.dirname(django.__file__)
import django
import os
os./usr/local/lib/python2.6/dist-packeages/
django.media(django.__file__)

File "<stdin>", line 1
os./usr/local/lib/python2.6/dist-packeages/
django.media(django.__file__)
^
SyntaxError: invalid syntax

this show the syntax error.......
where is the problem
>
> '/lib/python2.6/site-packages/django'
>
> Copy the directory called 'contrib/admin/media' from under that
> directory and put that with your site. Then set up the Alias to refer
> to it.
>
> You could set the Alias to refer to the directory in the installed
> Django installation if you want and not copy it, but copying it will
> allow you to modify the media files and not muck up your original
> Django installation.
>
> Graham

and httpd.conf file entiers

Alias /robots.txt /usr/local/wsgi/static/robots.txt
Alias /favicon.ico /usr/local/wsgi/static/favicon.ico

AliasMatch /([^/]*\.css) /usr/local/lib/python2.6/dist-packeages/
django/media/css$1

Alias /media/ /usr/local/lib/python2.6/dist-packeages/django/media/

<Directory /home/jagdeep>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/jagdeep/mysite/apache/django.wsgi

<Directory /home/jagdeep/mysite/apache>
Order allow,deny
Allow from all
</Directory>

Is this correct .???
my problem is not solve Sir , please help.

Kenneth Gonsalves

unread,
Jun 19, 2010, 6:12:58 AM6/19/10
to django...@googlegroups.com
On Saturday 19 June 2010 10:48:57 Jagdeep Singh Malhi wrote:
> packeages/
>
packages
--
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

Jagdeep Singh Malhi

unread,
Jun 19, 2010, 7:38:40 AM6/19/10
to Django users


On Jun 19, 3:12 pm, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> On Saturday 19 June 2010 10:48:57 Jagdeep Singh Malhi wrote:> packeages/
>
> packages

change this "packages" , but problem is not solve

Graham Dumpleton

unread,
Jun 19, 2010, 9:35:30 AM6/19/10
to Django users


On Jun 19, 3:18 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> On Jun 17, 5:03 pm, Graham Dumpleton <graham.dumple...@gmail.com>
> wrote:
>
>  i copy the media  directory in  my  "/home/yourname/mysite"
> directory.
>
> > Thus, run Python and go:
>
> > >>> import django
> > >>> import os
> > >>> os.path.dirname(django.__file__)
>
> import django
> import os
> os./usr/local/lib/python2.6/dist-packeages/
> django.media(django.__file__)
>
>  File "<stdin>", line 1
>     os./usr/local/lib/python2.6/dist-packeages/
> django.media(django.__file__)
>        ^
> SyntaxError: invalid syntax

I didn't tell you to run 'django.media()'.

> this show the  syntax  error.......
> where is the problem
>
>
>
> > '/lib/python2.6/site-packages/django'
>
> > Copy the directory called 'contrib/admin/media' from under that
> > directory and put that with your site. Then set up the Alias to refer
> > to it.
>
> > You could set the Alias to refer to the directory in the installed
> > Django installation if you want and not copy it, but copying it will
> > allow you to modify the media files and not muck up your original
> > Django installation.
>
> > Graham
>
> and httpd.conf   file entiers
>
> Alias /robots.txt /usr/local/wsgi/static/robots.txt
> Alias /favicon.ico /usr/local/wsgi/static/favicon.ico
>
> AliasMatch /([^/]*\.css) /usr/local/lib/python2.6/dist-packeages/
> django/media/css$1

You shouldn't need this AliasMatch.

> Alias /media/ /usr/local/lib/python2.6/dist-packeages/django/media/

If not copying files and referring to where they are in Django
package, this should be in your case:

Alias /media/ /usr/local/lib/python2.6/dist-packages/django/contrib/
admin/media/

<Directory /usr/local/lib/python2.6/dist-packages/django/contrib/
admin/media/>
Order deny,allow
Allow from all
</Directory>

This is presuming that 'os.path.dirname(django.__file__)' did actually
return:

/usr/local/lib/python2.6/dist-packages/django

Your above statements about what you got are plainly wrong and no
trust that anything is correct about what you did or said the results
were.

Graham

Jagdeep Singh Malhi

unread,
Jun 19, 2010, 1:06:52 PM6/19/10
to Django users


now my httpd.conf file is :-

Alias /media/ /usr/local/lib/python2.6/dist-packages/django/contrib/
admin/media/

<Directory /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
media/>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/jagdeep/mysite/apache/django.wsgi

<Directory /home/jagdeep/mysite/apache>
Order allow,deny
Allow from all
</Directory>

but my http://localhost/admin/ is not show in graphic format or not
use css files

its again show in this format

MY admin page (http://localhost/admin/)


Django administration
Welcome, Jagdeep. Change password / Log out
Site administration
Auth
Groups Add Change
Users Add Change
Polls
Polls Add Change
Sites
Sites Add Change

Recent Actions
My Actions

but i can do sir ???

Justin Myers

unread,
Jun 19, 2010, 1:36:50 PM6/19/10
to Django users
Have you set your MEDIA_ROOT, MEDIA_URL and ADMIN_MEDIA_PREFIX
settings in settings.py?

On Jun 19, 12:06 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> now my httpd.conf   file is :-
>
> Alias /media/ /usr/local/lib/python2.6/dist-packages/django/contrib/
> admin/media/
>
> <Directory /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
> media/>
> Order deny,allow
> Allow from all
> </Directory>
>
> WSGIScriptAlias / /home/jagdeep/mysite/apache/django.wsgi
>
> <Directory /home/jagdeep/mysite/apache>
> Order allow,deny
> Allow from all
> </Directory>
>
> but myhttp://localhost/admin/is  not show in graphic format or not

Graham Dumpleton

unread,
Jun 19, 2010, 8:25:41 PM6/19/10
to Django users


On Jun 20, 3:06 am, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> now my httpd.conf   file is :-
>
> Alias /media/ /usr/local/lib/python2.6/dist-packages/django/contrib/
> admin/media/
>
> <Directory /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
> media/>
> Order deny,allow
> Allow from all
> </Directory>

Change this to:

<Directory /usr/local/lib/python2.6/dist-packages/django/contrib/
admin/media/>
Options Indexes
Order deny,allow
Allow from all
</Directory>

Then access the URL:

/media/

on your web server via the browser. You should get a response
something like:

Index of /media

Name Last modified Size Description
Parent Directory -
css/ 09-Jun-2010 11:46 -
img/ 09-Jun-2010 11:46 -
js/ 09-Jun-2010 11:46 -

If you aren't, then that isn't where the media files are or directory
is not accessible to Apache user for some reason.

Then view the source of the response when access Django admin page.
You should see something like:

<link rel="stylesheet" type="text/css" href="/media/css/base.css" />
<link rel="stylesheet" type="text/css" href="/media/css/login.css" /
>

If you don't see the href link starting with '/media', then you have
fiddled the default settings in your Django settings.py to something
incompatible. The defaults are:

MEDIA_ROOT = ''
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/media/'

And if left untouched everything should work where media mounted at /
media in Apache.

Graham

> WSGIScriptAlias / /home/jagdeep/mysite/apache/django.wsgi
>
> <Directory /home/jagdeep/mysite/apache>
> Order allow,deny
> Allow from all
> </Directory>
>
> but myhttp://localhost/admin/is  not show in graphic format or not

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 5:08:10 AM6/20/10
to Django users


On Jun 19, 10:36 pm, Justin Myers <masterb...@gmail.com> wrote:
> Have you set your MEDIA_ROOT, MEDIA_URL and ADMIN_MEDIA_PREFIX
> settings in settings.py?
>
setting is :-
MEDIA_ROOT = '/home/your_name/mysite/media/'


MEDIA_URL = 'http://localhost/media'


ADMIN_MEDIA_PREFIX = '/media/'

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 5:34:03 AM6/20/10
to Django users
in which file i see these lines .

<link rel="stylesheet" type="text/css" href="/media/css/base.css" />
<link rel="stylesheet" type="text/css" href="/media/css/login.css" /

On Jun 20, 5:25 am, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 5:35:20 AM6/20/10
to Django users
Is these setting of my setting.py files are correct ?

setting is :-
MEDIA_ROOT = '/home/your_name/mysite/media/'

MEDIA_URL = 'http://localhost/media'

ADMIN_MEDIA_PREFIX = '/media/'

On Jun 20, 2:08 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>

Graham Dumpleton

unread,
Jun 20, 2010, 6:08:15 AM6/20/10
to Django users


On Jun 20, 7:34 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> in  which  file  i see  these lines .
>
>  <link rel="stylesheet" type="text/css" href="/media/css/base.css" />
> <link rel="stylesheet" type="text/css" href="/media/css/login.css" /

In your browser, when you request the admin page which isn't showing
the styling, use your browser to view the source code for that page as
the browser received it. This may be under view menu or you can right
click on page to get context menu and it will show option for viewing
source code.

Did you validate that the /media/ URL shows those directories?

Did you set those values in settings file back to their default?

Graham

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 7:17:39 AM6/20/10
to Django users


On Jun 20, 3:08 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> On Jun 20, 7:34 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
> wrote:
>
> > in  which  file  i see  these lines .
>
> >  <link rel="stylesheet" type="text/css" href="/media/css/base.css" />
> > <link rel="stylesheet" type="text/css" href="/media/css/login.css" /

yes these links are shown in source file
>
> In your browser, when you request the admin page which isn't showing
> the styling, use your browser to view the source code for that page as
> the browser received it. This may be under view menu or you can right
> click on page to get context menu and it will show option for viewing
> source code.
>
> Did you validate that the /media/ URL shows those directories?
>

/media is not show those directories
its display the files of my operating systems files under media
directriy me using ubuntu 10.04
> Did you set those values in settings file back to their default?

setting is :-
MEDIA_ROOT = '/home/your_name/mysite/media/'

MEDIA_URL = 'http://localhost/media'

ADMIN_MEDIA_PREFIX = '/media/'

is this correct or not ???

Graham Dumpleton

unread,
Jun 20, 2010, 8:00:43 AM6/20/10
to Django users


On Jun 20, 9:17 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
wrote:
> On Jun 20, 3:08 pm, Graham Dumpleton <graham.dumple...@gmail.com>
> wrote:
>
> > On Jun 20, 7:34 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
> > wrote:
>
> > > in  which  file  i see  these lines .
>
> > >  <link rel="stylesheet" type="text/css" href="/media/css/base.css" />
> > > <link rel="stylesheet" type="text/css" href="/media/css/login.css" /
>
> yes  these links are  shown in source file
>
>
>
> > In your browser, when you request the admin page which isn't showing
> > the styling, use your browser to view the source code for that page as
> > the browser received it. This may be under view menu or you can right
> > click on page to get context menu and it will show option for viewing
> > source code.
>
> > Did you validate that the /media/ URL shows those directories?
>
> /media is not show those directories
> its display  the   files  of  my operating systems files under media
> directriy me using  ubuntu 10.04

What do you mean by that? Post what the browser shows when you access:

/media/

on your site from your browser. Eg. access:

http://localhost/media/

if access it via localhost.

Note that the trailing slash is important.

There is no point just saying that it doesn't show what I suggest
should be seen, post what it does show instead.

Also post the output of running:

ls -las /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
media/

Please supply these bits of information, otherwise it is just getting
too hard to help you. May as well consult a tarot reader if you aren't
going to provide what is asked or offer up any other information which
may be relevant to working out what you have done wrong.

> > Did you set those values in settings file back to their default?
>
> setting is :-
> MEDIA_ROOT = '/home/your_name/mysite/media/'
>
> MEDIA_URL = 'http://localhost/media'
>
> ADMIN_MEDIA_PREFIX = '/media/'
>
> is this correct or not ???

As I pointed out before, the defaults should work without you having
changed them. What you have there isn't the defaults I get in settings
file when I generate a fresh Django site so you must have changed
them.

Set them back to what I said in other email for now. Ie.,

MEDIA_ROOT = ''
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/media/'

Graham

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 2:37:02 PM6/20/10
to Django users


On Jun 20, 5:00 pm, Graham Dumpleton <graham.dumple...@gmail.com>
output on browser:-
Index of /media
Name Last modified Size Description
Parent Directory -
css/ 08-Jun-2010 22:18 -
img/ 08-Jun-2010 22:18 -
js/ 08-Jun-2010 22:18 -
Apache/2.2.14 (Ubuntu) Server at localhost Port 80

> Note that the trailing slash is important.
>
> There is no point just saying that it doesn't show what I suggest
> should be seen, post what it does show instead.
>
> Also post the output of running:
>
>   ls -las /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
> media/
>
output of this :-
drwxr-sr-x 5 root staff 4096 2010-06-08 22:18 .
4 drwxr-sr-x 6 root staff 4096 2010-06-08 22:18 ..
4 drwxr-sr-x 2 root staff 4096 2010-06-08 22:18 css
4 drwxr-sr-x 4 root staff 4096 2010-06-08 22:18 img
4 drwxr-sr-x 3 root staff 4096 2010-06-08 22:18 js


> Please supply these bits of information, otherwise it is just getting
> too hard to help you. May as well consult a tarot reader if you aren't
> going to provide what is asked or offer up any other information which
> may be relevant to working out what you have done wrong.
>
> > > Did you set those values in settings file back to their default?
>
> > setting is :-
> > MEDIA_ROOT = '/home/your_name/mysite/media/'
>
> > MEDIA_URL = 'http://localhost/media'
>
> > ADMIN_MEDIA_PREFIX = '/media/'
>
> > is this correct or not ???
>
> As I pointed out before, the defaults should work without you having
> changed them. What you have there isn't the defaults I get in settings
> file when I generate a fresh Django site so you must have changed
> them.
>
> Set them back to what I said in other email for now. Ie.,
>
>   MEDIA_ROOT = ''
>   MEDIA_URL = ''
>   ADMIN_MEDIA_PREFIX = '/media/'
>
> Graham
>
Now , I set default value .

Jagdeep Singh Malhi

unread,
Jun 20, 2010, 2:41:18 PM6/20/10
to Django users
Sir thanks very much indeed , now its works.........
thanks.



On Jun 20, 11:37 pm, Jagdeep Singh Malhi <singh.malh...@gmail.com>
Reply all
Reply to author
Forward
0 new messages