外部 CSS 在 Python 项目中的 HTML 中不起作用

夏尔马

我用外部 CSS 文件替换了<style>标记base.html其中base.html有一个链接到不同 HTML 页面的菜单。当我单击任何菜单项时,页面正在加载但不是 CSS。

我尝试<link>homealter.htmlCSS 中使用标记来工作,但它不起作用。

基本文件

<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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我的 CSS 和 JS 外部文件在我的项目中不起作用

html排序的列表属性“开始”和“类型”在外部CSS中不起作用

外部样式表 css 在 shadow dom(HTML Web 组件)中不起作用

CSS Margin 在 React typescript 项目中不起作用

HTML CSS在Safari中不起作用

#checkbox:checked〜项目在使用CSS的html网页中不起作用

index.html 中包含的 JS 在 VUE 项目中的 main.js 中不起作用

CSS内联到外部CSS文件中(不起作用)

HTML 5 Canvas在我的项目中不起作用,但是相同的代码在JSFiddle中起作用吗?

外部CSS在IE11中不起作用

外部Javascript,CSS在Eclipse中不起作用

外部 Javascript 文件在 HTML 文件中不起作用

外部 JS 文件在我的 HTML 文件中不起作用

尝试在nuxt项目中安装外部javascript库(choreographer-js),但不起作用

CSS 外部文件不起作用

CSS 命令在 CSS 文件中不起作用,但在主 HTML 中起作用

相同的代码在不同的IDE中不起作用-html,css

Vue绑定和HTML中的CSS不起作用

HTML CSS相对位置在gmail中不起作用

标签在HTML CSS Javascript中不起作用

HTML 和 CSS 文件在 chrome 中不起作用,错误?

填充在水平线css html中不起作用

在Famo.us项目中包括外部CSS文件

HTML5必需的属性在使用CLI安装的Angular 2项目中不起作用

Flask 的 HTML 花括号中的 Python 代码不起作用

如何从WordPress项目中编码的图像HTML标记中删除通用CSS属性?

HTML / CSS样式标签不起作用

HTML / CSS分页符不起作用

HTML / CSS - (浮动:左)不起作用