Django CSS在我更改URL时停止工作

2024-03-28 15:41:15 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在我的网站上遇到了一个问题,然后我创建了两个独立的html页面。然后我编辑了网址.py因此,网址将是不同的2页,但css停止工作,如果我这样做。下面是我的代码,以后我会详细解释。你知道吗

我的一部分头.html你知道吗

<!-- 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>

如何在每个html页面上包含head

{% include "textchange/head.html" %}

导致问题的两个URL

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"),

所以以上是我的网址是如何设置在目前,我意识到这将永远只会到目前的联系。当我像这样更改URL时:

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"),

CSS对这两个页面都停止工作。你知道吗

最初,在我有2个页面之前,url如下所示:

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

你知道吗视图.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)
        )

为什么CSS会停止工作?你知道吗

谢谢。你知道吗


Tags: nameurlobjectshtmlscript页面filterresults
1条回答
网友
1楼 · 发布于 2024-03-28 15:41:15

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

你不应该为你的静态链接使用相对URL。相反,使用绝对值:

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

更好的是,使用{% static %}标记,它从设置文件中获取静态URL的值。你知道吗

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

相关问题 更多 >