开发者

django static files

I have in my urls.py l开发者_StackOverflow社区ine:

if settings.DEBUG==True:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT})
    )

In my settings file something like this:

STATIC_DOC_ROOT = os.path.join(os.path.dirname(__file__),'static').replace('\\','/')

And when I go to / in my page everything work just great. And when I click a link from / to anther page I don't have CSS applied because of 404 error. He tries to load a CSS file from that URL.

http://localhost:8000/show/sth/static/style.css

Here is my urls.py for this method

(r'^show/(?P<subject>[^/]+)/(?P<title>[^/]+)$','show'),

I have url /links and css works just in this one template it does not work. It seems that these parameters messing something up. Any suggestions why this fails? Here is my template code:

{% extends "szkielet.html" %}
{% block tresc %}
    <div id="content">
        <div class="post">
            <h2 class="title">{{ notatka.tytul }}</h2>
                <p class="meta"><span class="author">{{ notatka.user.name }}</span> <span class="date">July 07, 2010</span>&nbsp;<span class="links"><a href="#" title="">Comments</a></span></p>
                <div class="entry">
                    <p>{{ notatka.tresc }}</p>
            </div>
        </div>
    </div>
{% endblock %}

Szkielet.html - it is my base

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Perfect Blemish      by Free CSS Templates</title>
<link href="{{ MEDIA_URL }}style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

Here is part responsible for CSS it is only one style sheet .


URL's could potentially be set to override the static url path but that's not the case here! So your URL conf doesn't have anything to do with this.

The core problem is that your template is rendering an incorrect URL: http://localhost:8000/show/sth/static/style.css should be http://localhost:8000/static/style.css correct?

Show us your template since that seems to be the problem. Sounds to me like you just have a relative URL set for your CSS instead of absolute or /static/style.css

What is your {{ media_url }}? It's supposed to be absolute, and begin with a /

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜