1

I'm trying to link my base.css to base.html file. As I'm doing this but it doesn't reflect any changes. If it is possible, what'll be the correct code?

I use header & footer tag in the base.html file and there are no. of different properties I'm implementing in the project. So the separate CSS file would be better rather than using inline styling or internal style sheet. But it isn't working.

syntax of code used:

`{% load static %}
  <html>
  <head>
    <link rel = 'stylesheet' href = '{% static 'css/base.css' %}'>
  </head>
  <header>
    ......
    ......
  </header>
  {% block content %}
  {% endblock %}
  <footer>....
  </footer>
  </html>'

Also, when I tried to make a separate .css file for base.html. It didn't work. So I'm confused now. It seems like you can't link two template tag files - base.html (Common Header & Footer) for every web pages & base.css for styling of every web pages.

3
  • 1
    This may be a duplicate stackoverflow.com/questions/26237563/… although this post is 4years ago Commented Oct 31, 2018 at 13:33
  • 1
    Hello and welcome to SO. There are a number of informations missing from your question so it's impossible to answer it as is. Please edit your post to add the following informations: 1/ which django and python version, 2/ is this when running the development server (./manage.py runserver) or behind a front server (nginx, apache etc), 3/ where are you css files stored, 4/ are your settings STATICFILES_DIR etc correctly configured, and 5/ did you carefully read the doc regarding static files ? Commented Oct 31, 2018 at 13:35
  • Oh and yes: when you inspect the rendered page in your browser, do you have an url for your link tag, and if yes what's the response status code ? Commented Oct 31, 2018 at 15:10

2 Answers 2

2

Using <link rel = 'stylesheet' href = '{% static 'css/base.css' %}'> is the correct way of linking a css file.

Assuming I am reading your question correctly, you may be having an issue with caching in your browser if certain effects are not appearing. I would recommend starting with disabling your cache in chrome for development. Right click > inspect element > Network > "Disable Cache"

If this is not the issue you are having then you may need to rephrase your question to explain what is not working correctly.

Sign up to request clarification or add additional context in comments.

Comments

-1

Your CSS is necessary in base.css ? If not one solution is in admin.py add class Media: css = { 'all': ('css/bass.css',) }

1 Comment

This doesn't answer the question - the OP made no mention of the admin in his question and is clearly talking about a template rendered by public views -, and would not solve the problem anyway - if the staticfile app can't resolve the path to his css file then it will not work in the admin either.

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.