Hi,

STATIC_URL is not working in your template because the template does not get 
the RequestContext, which has all the variables in it.

use the render shortcut [1] instead of render_to_reponse

BTW: It seems you are using the development version. You should change to 1.3.1

Does this help?

[1]  https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render


On Nov 23, 2011, at 7:33 , Guillaume Chorn wrote:

> Hi,
> 
> The location of my CSS file is 
> /Users/guillaumechorn/Documents/project/myapp/static/stylesheet.css.  Sorry, 
> I may have missed you asking for this earlier.
> 
> Here is my views.py:
> 
> http://dpaste.com/660653/
> 
> When I hardcode the disk location of the CSS file in the template (like so: 
> <link rel="stylesheet" 
> href="/Users/guillaumechorn/Documents/project/myapp/static/stylesheet.css" 
> type="text/css" />), the CSS shows up if I open the template file directly 
> using a browser.  But it still doesn't show up when loading up the page on 
> the development server.
> 
> thanks,
> Guillaume
> 
> On Wed, Nov 23, 2011 at 9:57 AM, Ivo Brodien <[email protected]> wrote:
> Hi,
> 
> looks fine.
> 
> yes, show your views.py 
> 
> and you can also hardcode the STATIC_URL in the template to see if the path: 
> src=“/static/stylesheet.css” works.
> 
> or simply open http://127.0.0.1:8000/static/stylesheet.css in your browser.
> 
> Again: Where is that CSS file on your disk?
> 
> On Nov 23, 2011, at 2:46 , Guillaume Chorn wrote:
> 
>> Sorry, I think I made something confusing.  In my original file, I only 
>> pasted the URL pattern for the site homepage.  However, this is not the page 
>> I'm trying to style (or link to the CSS file).  The page I'm trying to link 
>> to the CSS file is a separate one, which I have previously referred to as 
>> http://127.0.0.1:8000/view/, but which I will hereafter refer to as 
>> http://127.0.0.1:8000/items/ (and will now include below).  I previously 
>> used the term "view" to imply a general myapp.views.view, but will hereafter 
>> refer to it as myapp.views.items.  Hope that makes sense.  I've used dpaste 
>> to share my code as suggested.
>> 
>> Here is my settings.py file:
>> 
>> http://dpaste.com/660563/
>> 
>> Here is the template which I want to style:
>> 
>> http://dpaste.com/660565/
>> 
>> And here is my urls.py file:
>> 
>> http://dpaste.com/660568/
>> 
>> Let me know if anything else is needed, such as the views.py file or 
>> something.
>> 
>> thanks,
>> Guillaume
>> 
>> On Wed, Nov 23, 2011 at 7:33 AM, Ivo Brodien <[email protected]> wrote:
>> In your original post you had the url like this:
>> 
>>> (r'^home/$','myapp.views.homepage'),
>> 
>> than your the url starts with view instead of home so there might be 
>> something wrong.
>> 
>> just paste these files into somthing like dpaste.com
>> 
>> - settings.py
>> - myapp.views.homepage
>> - urls.py
>> 
>> cheers
>> 
>> 
>> On Nov 23, 2011, at 0:29 , Guillaume Chorn wrote:
>> 
>>> Thank you Ivo.  Your suggestion makes a lot of sense so I tried it out.  
>>> Unfortunately, after adding TEMPLATE_CONTEXT_PROCESSORS and its associated 
>>> tuple into the settings.py file, I tried to restart the development server 
>>> to see if it worked and it didn't.  I checked the page source again and 
>>> it's still looking for /view/stylesheet.css.  Am I missing something else?
>>> 
>>> thanks,
>>> Guillaume
>>> 
>>> On Tue, Nov 22, 2011 at 10:42 PM, Ivo Brodien <[email protected]> wrote:
>>> 
>>>> Finally, I have another question.  In my settings.py file, there is 
>>>> actually no section for TEMPLATE_CONTEXT_PROCESSORS.  I have noticed in 
>>>> the documentation
>>> 
>>> yes.
>>> 
>>> put this in there:
>>> 
>>> ("django.contrib.auth.context_processors.auth",
>>> "django.core.context_processors.debug",
>>> "django.core.context_processors.i18n",
>>> "django.core.context_processors.media",
>>> "django.core.context_processors.static",
>>> "django.core.context_processors.tz",
>>> "django.contrib.messages.context_processors.messages")
>>> 
>>> and try again.
>>> 
>>> What happens in your template is that {{ STATIC_URL }} is empty because the 
>>> context processor ““django.core.context_processors.static”” did not put the 
>>> STATIC_URL into the context. so your path to the file becomes: 
>>> /view/stylesheet.css instead of /static/stylesheet.css
>>> 
>>> You have to put the CSS file in a directory called static as mentioned 
>>> before.
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

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

Reply via email to