0

I replaced <style> tag in base.html with an external CSS file. In base.html there is a menu which links to different HTML pages. When I click on any menu item, the page is loading but not CSS.

I tried using <link> tag in homealter.html for CSS to work, but it doesn't work.

base.html

<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 %}

It worked earlier because there was internal CSS in base.html. I need base_style.css to work whenever menu items are selected i.e., in other pages as well.

11
  • 1
    where do you add <link> ? When you open page in browser and use Ctrl+U to see source code - do you see this link in HTML ? Copy this link from HTML and open in new card in browser - is it loading ? Commented Apr 20, 2019 at 14:32
  • I added <link> in div and also at the top, I also created a body tag, but nothing worked so far. Commented Apr 20, 2019 at 14:35
  • I don't see <link> in <div>. I see only one link to "../static/css/base_style.css" but it is not external link. Or maybe you mean external folder on disk - browser doesn't have access to external folders on disk for security reason. Commented Apr 20, 2019 at 14:39
  • In homealter.html, <link> is not working, and I removed it. I'll add it again. Commented Apr 20, 2019 at 14:42
  • to resolve problem you have to show code which you run and full errors which you get. Commented Apr 20, 2019 at 14:44

1 Answer 1

2

You should have it just in base.html, but the full path (not relative):

<link href="/static/css/base_style.css"...

or better:

{% load static %}
<link href="{% static 'css/base_style.css' %}"...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.