我用外部 CSS 文件替换了<style>
标记base.html
。其中base.html
有一个链接到不同 HTML 页面的菜单。当我单击任何菜单项时,页面正在加载但不是 CSS。
我尝试<link>
在homealter.html
CSS 中使用标记来工作,但它不起作用。
基本文件
<link href="../static/css/base_style.css" rel="stylesheet" type="text/css">
<div class="menu">
<table>
<tr>
{% with request.resolver_match.url_name as url_name %}
<td class="{% if url_name == 'home' %}active{% endif %}"><a href="{% url 'home' %}">Resource Wise Analysis</a></td>
<td class="{% if url_name == 'homealter' %}active{% endif %}"><a href="{% url 'homealter' %}">Land Distance Analysis</a></td>
<td class="{% if url_name == 'graphsone' %}active{% endif %}"><a href="{% url 'graphsone' %}">Water Type Based Analysis</a></td>
<td class="{% if url_name == 'graphstwo' %}active{% endif %}"><a href="{% url 'graphstwo' %}">Land Distance Analysis</a></td>
<td><a href="{% url 'logout' %}">Logout</a></td>
{% endwith %}
</tr>
</table>
</div>
{% block mains %}
{% endblock %}
</body>
homealter.html
{% extends 'base.html' %}
{% block mains %}
{% load staticfiles %}
<link href="../static/css/base_style.css" rel="stylesheet" type="text/css">
<div class="contnt">
<table>
<tr>
<th>Land Size</th>
<th>Land Distances Count</th>
<!--<th>Details</th>-->
</tr>
{% for index, row in yeye.iterrows %}
<tr>
<td><p>{{index}}</p></td>
<td>{{row.Distance}}</td>
<!--<td><a href="{% url 'yearwise' index %}">View Details</a></td>-->
{% endfor %}
</tr>
</table>
<img src="{% static 'images/im1.jpg' %}">
</div>
{% endblock %}
它工作得更早,因为base.html
. base_style.css
只要选择菜单项即,在其他页面中也需要工作。
你应该只在 base.html 中,但完整路径(不是相对的):
<link href="/static/css/base_style.css"...
或更好:
{% load static %}
<link href="{% static 'css/base_style.css' %}"...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句