Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 30, 2010 18:21:14

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


I am running Django 1.2.3 -- python -c "import django; print
django.get_version()" I basically need to know what logs to look at to
fix a css file not loading.

I am trying to load a css file in my base template

<html>
<!-- Test Comment -->
<head>
<title>{% block title %}Town of Arlington Water Department AMR
System{% endblock %} </title>
<link rel="stylesheet" type="text/css" href="/static_media/
amr.css" />
</head>

Here's the css file -- you could say it's a "test file".

body{ background-color: gray;}
p { color: blue; }
h3{ color: white; }

In urls.py this is inserted into

urlpatterns = patterns('',

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/home/amr/django'}),

Nothing loaded. Then, I tried setting STATIC_DOC_ROOT = '/home/amr/
django/static_media' in settings.py and in urls.py

from django.conf import settings
...
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),

and gotten this error

AttributeError at /

'Settings' object has no attribute 'STATIC_DOC_ROOT'

Thanks for any help or pointers.

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

Offline

#2 Nov. 30, 2010 22:14:17

Robert S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


Well - that's one way
A simpler way is to use your settings.py file to point to your media,
and remove all reference to .css from your url.py files

...

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/path_to_media_root/static_media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash if there is a path component (optional in other
cases).
# Examples: "http://media.lawrence.com";, "http://example.com/media/";
MEDIA_URL = '/static_media/'

...

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

Offline

#3 Dec. 1, 2010 09:52:07

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


On Tue, Nov 30, 2010 at 6:21 PM, octopusgrabbus
<old_road_f...@verizon.net> wrote:
> I am running Django 1.2.3 -- python -c "import django; print
> django.get_version()" I basically need to know what logs to look at to
> fix a css file not loading.
>
> I am trying to load a css file in my base template
>
> <html>
>    <!-- Test Comment -->
>    <head>
>        <title>{% block title %}Town of Arlington Water Department AMR
> System{% endblock %} </title>
>        <link rel="stylesheet" type="text/css" href="/static_media/
> amr.css" />
>   </head>

So you are requesting the file '/static_media/amr.css'

>
> Here's the css file -- you could say it's a "test file".
>
> body{ background-color: gray;}
> p { color: blue; }
> h3{ color: white; }
>
> In urls.py this is inserted into
>
> urlpatterns = patterns('',
>
>    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
>        {'document_root': '/home/amr/django'}),
>

and you are enabling file serving from a path starting '/site_media/'
(assuming this is your root urlconf).

Is it clear why it isn't working now? 'site_media' != 'static_media'.

In your django dev console, it shows each URL requested, and the HTTP
return code. It will look something like this:

"GET /static_media/amr.css HTTP/1.1" 404 2572

The first part ('/static_media/') has to match the URL you put in your
urlconf, and the second part ('amr.css') must exist in the folder that
you specify as document_root (or subfolder etc).

This isn't exactly rocket science, just make everything match up, and it works.

BTW, in your template you can use {{ MEDIA_URL }} to get the prefix to
your media - assuming you have correctly set settings.MEDIA_URL, and
have django.core.context_processors.media in
TEMPLATE_CONTEXT_PROCESSORS and use a RequestContext to render with,
which is a few caveats I guess :)

Cheers

Tom

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

Offline

#4 Dec. 1, 2010 15:01:35

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


Thanks for your comments:

Here are the changes I've made, and it still does not load:

A directory css is under the main media directory

a...@h2oamr:~/django/amr$ ls -l media/css
total 4
-rw-r--r-- 1 amr amr 72 Nov 30 14:45 amr.css


Here are the settings.py changes:

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/amr/django/media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash if there is a path component (optional in other
cases).
# Examples: "http://media.lawrence.com";, "http://example.com/media/";
MEDIA_URL = '/media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure
to use a
# trailing slash.
# Examples: "http://foo.com/media/";, "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

ROOT_URLCONF = 'amr.urls'
STATIC_DOC_ROOT = '/home/amr/django/media'

And here's the reference to it in the base template.

<html>
<!-- Test Comment -->
<head>
<title>{% block title %}Town of Arlington Water Department AMR
System{% endblock %} </title>
<link rel="stylesheet" type="text/css" href="css/amr.css" />
</head>



On Dec 1, 4:51 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Tue, Nov 30, 2010 at 6:21 PM, octopusgrabbus
>
> <old_road_f...@verizon.net> wrote:
> > I am running Django 1.2.3 -- python -c "import django; print
> > django.get_version()" I basically need to know what logs to look at to
> > fix a css file not loading.
>
> > I am trying to load a css file in my base template
>
> > <html>
> >    <!-- Test Comment -->
> >    <head>
> >        <title>{% block title %}Town of Arlington Water Department AMR
> > System{% endblock %} </title>
> >        <link rel="stylesheet" type="text/css" href="/static_media/
> > amr.css" />
> >   </head>
>
> So you are requesting the file '/static_media/amr.css'
>
>
>
> > Here's the css file -- you could say it's a "test file".
>
> > body{ background-color: gray;}
> > p { color: blue; }
> > h3{ color: white; }
>
> > In urls.py this is inserted into
>
> > urlpatterns = patterns('',
>
> >    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
> >        {'document_root': '/home/amr/django'}),
>
> and you are enabling file serving from a path starting '/site_media/'
> (assuming this is your root urlconf).
>
> Is it clear why it isn't working now? 'site_media' != 'static_media'.
>
> In your django dev console, it shows each URL requested, and the HTTP
> return code. It will look something like this:
>
> "GET /static_media/amr.css HTTP/1.1" 404 2572
>
> The first part ('/static_media/') has to match the URL you put in your
> urlconf, and the second part ('amr.css') must exist in the folder that
> you specify as document_root (or subfolder etc).
>
> This isn't exactly rocket science, just make everything match up, and it
> works.
>
> BTW, in your template you can use {{ MEDIA_URL }} to get the prefix to
> your media - assuming you have correctly set settings.MEDIA_URL, and
> have django.core.context_processors.media in
> TEMPLATE_CONTEXT_PROCESSORS and use a RequestContext to render with,
> which is a few caveats I guess :)
>
> Cheers
>
> Tom

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

Offline

#5 Dec. 1, 2010 15:02:33

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


On Wed, Dec 1, 2010 at 2:48 PM, octopusgrabbus
<old_road_f...@verizon.net> wrote:
> Thank you. I've done made changes according to your suggestions, but
> the css appears not to load. I am using apache, not the built-in web
> server.
>

Are you expecting django to serve the file through apache or apache to
directly serve the file?

How have you configured apache?

What is output in apache's access log when you try to access the file?

You really need to provide more information. "It doesn't work" doesn't
really help debug.

Cheers

Tom

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

Offline

#6 Dec. 1, 2010 15:06:14

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


Thank you. I've done made changes according to your suggestions, but
the css appears not to load. I am using apache, not the built-in web
server.

On Nov 30, 5:14 pm, Robert S <rob...@robert-stuart.me.uk> wrote:
> Well - that's one way
> A simpler way is to use your settings.py file to point to your media,
> and remove all reference to .css from your url.py files
>
> ...
>
> # Absolute path to the directory that holds media.
> # Example: "/home/media/media.lawrence.com/"
> MEDIA_ROOT = '/path_to_media_root/static_media/'
>
> # URL that handles the media served from MEDIA_ROOT. Make sure to use
> a
> # trailing slash if there is a path component (optional in other
> cases).
> # Examples: "http://media.lawrence.com";, "http://example.com/media/";
> MEDIA_URL = '/static_media/'
>
> ...

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

Offline

#7 Dec. 1, 2010 15:12:48

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


On Wed, Dec 1, 2010 at 3:02 PM, Tom Evans <tevans...@googlemail.com> wrote:
> Are you expecting django to serve the file through apache or apache to
> directly serve the file?
>
> How have you configured apache?
>
> What is output in apache's access log when you try to access the file?
>
> You really need to provide more information. "It doesn't work" doesn't
> really help debug.
>
> Cheers
>
> Tom
>

I don't mean to repeat myself, but you still haven't given any of this
information, so there are diminishing returns to helping you further.
How you have configured apache to serve django affects this issue, and
without the information, I'm just speculating.

Tom

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

Offline

#8 Dec. 1, 2010 15:18:38

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


Your right. I should have looked in the logs, and the directory path
is wrong.

10.100.0.88 - - "GET /css/amr.css HTTP/
1.1" 404 228
6 "http://amrserver:8002/"; "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
1.9.2.12)
Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12"


On Dec 1, 10:02 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, Dec 1, 2010 at 2:48 PM, octopusgrabbus
>
> <old_road_f...@verizon.net> wrote:
> > Thank you. I've done made changes according to your suggestions, but
> > the css appears not to load. I am using apache, not the built-in web
> > server.
>
> Are you expecting django to serve the file through apache or apache to
> directly serve the file?
>
> How have you configured apache?
>
> What is output in apache's access log when you try to access the file?
>
> You really need to provide more information. "It doesn't work" doesn't
> really help debug.
>
> Cheers
>
> Tom

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

Offline

#9 Dec. 1, 2010 15:49:51

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


My question is what do I need to do to straighten out the media path,
so I can load amr.css.

When trying to load amr.css, my application gets a 404.
10.100.0.88 - - "GET /css/amr.css HTTP/
1.1" 404 228
6 "http://amrserver:8002/"; "Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:
1.9.2.12)
Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12"

Here's where amr.css is loaded in base.html

<html>
<!-- Test Comment -->
<head>
<title>{% block title %}Town of Arlington Water Department AMR
System{% endblock %} </title>
<link rel="stylesheet" type="text/css" href="css/amr.css" />
</head>

Here are the paths in settings.py

MEDIA_ROOT = '/home/amr/django/amr/'
MEDIA_URL = 'media/'
ADMIN_MEDIA_PREFIX = '/media/'

The path to amr.css is /home/amr/django/amr/media/css

and here is the configuration from apache

Listen 8002
<VirtualHost _default_:8002>
Alias /media /home/amr/django/amr/media
<Location />
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /tmp/.python_eggs
PythonOption django.root /home/amr/django/amr
PythonPath " +
sys.path"
PythonDebug On

Any thoughts or pointers would be appreciated.

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

Offline

#10 Dec. 1, 2010 21:05:40

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Loading CSS


Many thanks to the replies and everyone's patience. I can't see the
9th response to this thread because Google Groups appears to be off
line, but here's what I've done to get amr.css to load:

1) Here is the base template portion that loads the css file:

<html>
<!-- Test Comment -->
<head>
<title>{% block title %}Town of Arlington Water Department AMR
System{% endblock %} </title>
<link rel="stylesheet" type="text/css" href="http://localhost:8003/css/amr.css" />
</head>

2) Here is the apache config file. This is choice appears to be in
line with the Django documentation, because Django recommends not
serving static content from the same document root.

Listen 8003
<VirtualHost _default_:8003>
DocumentRoot "/var/www/amr/media"
<Directory "/var/www/amr/media">
Options +Includes
</Directory>

Basically media is a symlink
media -> /home/amr/django/amr/media

I get a 200 from loading the css file

body{ background-color: blue;}
p { color: blue; }
h3{ color: white; }

I picked blue just so I'd see a drastic change. It's not my final
choice.

My question is why don't I see a change?

Thanks.
cmn


On Dec 1, 10:12 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, Dec 1, 2010 at 3:02 PM, Tom Evans <tevans...@googlemail.com> wrote:
> > Are you expecting django to serve the file through apache or apache to
> > directly serve the file?
>
> > How have you configured apache?
>
> > What is output in apache's access log when you try to access the file?
>
> > You really need to provide more information. "It doesn't work" doesn't
> > really help debug.
>
> > Cheers
>
> > Tom
>
> I don't mean to repeat myself, but you still haven't given any of this
> information, so there are diminishing returns to helping you further.
> How you have configured apache to serve django affects this issue, and
> without the information, I'm just speculating.
>
> Tom

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

Offline

Board footer

Moderator control

Enjoy the 24th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support