html中的重定向失败

时间:2014-12-18 05:10:08

标签: python html css django

我有一个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“notificationContainer”中有“Home”。当我点击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;
}

2 个答案:

答案 0 :(得分:0)

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

如果你的家有一个观点,那么:

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

如果它只是一个模板,你可以使用这样的东西:

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

答案 1 :(得分:0)

我认为你误解了Ebtessam的答案。您不仅需要配置URL,还需要在HTML中正确引用该URL。

你有:

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

更改为:

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

以上假设您在网址中定义了类似于以下内容的内容:

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

注意name="home"。在模板中,您引用具有该名称的视图,因此:

{% url 'home' %}