Django - 当我更改网址时,CSS停止工作

Pro*_*joe 5 css python django url

所以我在我的网站上遇到了一个问题,然后我创建了两个单独的html页面.然后我编辑了urls.py,因此2页的网址会有所不同,但如果我这样做,css就会停止工作.我的代码如下,之后我会更详细地解释.

我头部的一部分

<!-- Bootstrap core CSS -->


<link href="../../static/textchange/index.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="../../static/textchange/jumbotron.css" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="../../static/textchange/index.js"></script>
Run Code Online (Sandbox Code Playgroud)

我如何在每个html页面上包含头部

{% include "textchange/head.html" %}
Run Code Online (Sandbox Code Playgroud)

这两个网址造成了问题

url(r'^results/(?P<uisbn>(\w)+)/(?P<uuser>(\w)+)$', views.contactpost, name="contactpost"),
url(r'^results/(?P<uisbn>(\w)+)/(?P<uuser>(\w)+)$', views.contactwish, name="contactwish"),
Run Code Online (Sandbox Code Playgroud)

所以上面是我的网址设置目前的方式,我意识到这只会转到当前的联系信息.当我更改这样的网址时:

url(r'^results/(?P<uisbn>(\w)+)/post/(?P<uuser>(\w)+)$', views.contactpost, name="contactpost"),
url(r'^results/(?P<uisbn>(\w)+)/wish/(?P<uuser>(\w)+)$', views.contactwish, name="contactwish"),
Run Code Online (Sandbox Code Playgroud)

CSS停止为两个页面工作.

最初在我有2页之前,网址看起来像这样:

url(r'^results/(?P<uisbn>(\w)+)/(?P<uuser>(\w)+)$', views.contact, name="contact"),
Run Code Online (Sandbox Code Playgroud)

Views.py

@login_required
def contactpost(request, uuser, uisbn):
    ltextbook = Textbook.objects.filter(isbn = uisbn)
    text = ltextbook[0]
    luser = User.objects.filter(username = uuser)
    quser = luser[0]
    post = Posting.objects.filter((Q(user = quser) & Q(textbook = ltextbook)))
    posting = post[0]
    return render_to_response(
        'textchange/contactpost.html',
        locals(),
        context_instance=RequestContext(request)
        )

@login_required
def contactwish(request, uuser, uisbn):
    ltextbook = Textbook.objects.filter(isbn = uisbn)
    text = ltextbook[0]
    luser = User.objects.filter(username = uuser)
    quser = luser[0]
    wish = Wishlist.objects.filter((Q(user = quser) & Q(textbook = ltextbook)))
    wishlist = wish[0]
    return render_to_response(
        'textchange/contactwish.html',
        locals(),
        context_instance=RequestContext(request)
        )
Run Code Online (Sandbox Code Playgroud)

为什么CSS会停止工作?

谢谢.

Dan*_*man 7

static的URL上升了两个目录; 但是你的路径现在是三个目录深,所以URL是错误的.

您不应该为静态链接使用相对URL.相反,使用绝对的:

<link href="/static/textchange/index.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)

更好的是,使用{% static %}从您的设置文件中获取STATIC_URL值的标记.

<link href="{% static "textchange/index.css" %}" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)