html中的重定向失败

2024-09-28 01:27:38 发布

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

我有一个html:

{% load staticfiles %}
<div style="margin:0 auto; width:900px">
<ul id="nav">
<li id="notification_li">
<a href="#" id="notificationLink">
<div id="notify"> <img src="{% static "images/notification.png" %}" width="20" height="20" />
{% if unseen_notifications.count > 0 %}
    <span id="notification_count">
    {{unseen_notifications.count}}</span>
{% endif %}
</div></a>
<div id="notificationContainer">
<div id="notificationTitle">Inbox</div>
<div id="notificationsBody">
<a href="/home/">Home</a>
</div>
<div id="notificationFooter"><a href="{% url "ask_question" %}">See All</a></div>
</div>
</li>
</ul>
</div>

这里我有“家”里面的id“通知容器”。当我单击Home时,它不会重定向,但会在“notificationContainer”外部重定向。通知容器内我愿意把通知。但它没有重定向。你知道吗

我的风格:

#notification_li{position:relative}
#notificationContainer {
background-color: #FFF;
border: 1px solid rgba(100, 100, 100, .4);
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
overflow: visible;
position: absolute;
top: 30px;
margin-left: -170px;
width: 400px;
z-index: 11;
display: none;
}
#notificationContainer:before {
content: '';
display: block;
position: absolute;
width: 0;
height: 0;
border: 10px;
margin-top: -20px;
margin-left: 188px;
}
#notificationTitle {
z-index: 1000;
font-weight: bold;
padding: 8px;
font-size: 15px;
background-color: #ffffff;
width: 384px;
border-bottom: 1px solid #dddddd;
}
#notificationsBody {
padding: 0px 0px 0px 0px !important;
margin: 0px;
min-height:300px;
font-size:14px; 
display: block;
}
#notificationsBody a{ color: #000;}
#notification_count {
padding: 3px 7px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: 0px;
border-radius: 20px;
position: absolute;
margin-top: -7px;
font-size: 11px;
}
#notificationFooter {
background-color: #e9eaed;
text-align: center;
font-weight: bold;
padding: 8px;
font-size: 12px;
border-top: 1px solid #dddddd;
}

Tags: margindividtopcountpositionnotificationli
2条回答

我想你误解了艾伯特萨姆的回答。不仅需要配置URL,还需要在HTML中正确引用该URL。你知道吗

您有:

<a href="/home/">Home</a>

更改为:

<a href="{% url 'home' %}">Home</a>

以上假设您在URL中定义的内容类似于:

url(r'^home/',views.your_home_view_here, name="home"),

请注意name="home"。在模板中,使用该名称引用视图,因此:

{% url 'home' %}

你需要在你的网站中定义一个网址网址.py 如果你想像这样使用它<a href="{% url "ask_question" %}">,那么给你的url加个名字,像这样使用它<a href="{% url "home" %}">

如果你的家能看到风景,那么:

url(r'^people/', "myapp.views.people", name="people"), 

如果只是一个模板,您可以使用以下内容:

url(r'^home/',TemplateView.as_view(template_name="homepage.html"), name="home"),

相关问题 更多 >

    热门问题