Python Forum
[Django] css file is not applying to the page - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: [Django] css file is not applying to the page (/thread-26666.html)



[Django] css file is not applying to the page - SheeppOSU - May-09-2020

I have a link to a css file in my html but it's not applying to the site. There are no errors and when I go to inspect -> sources the css file is not there, so I see the problem, but I don't see the solution. Thanks in advance for any help.
This is the base html file that loads in the css.
{% load static %}

<link rel="'stylesheet" type="text/css" href="{% static 'polls/styles.css' %}">
<!DOCTYPE html>
<html lang="en">
.
.
.
This is the css file in case you want to see it
li a {
    color: green;
}

body {
    
}

.question-display {
    border-color: black;
    border-width: 5px;
    position: center;
}

.question-link {
    
}
.
.
.
This is the line of code I have in settings STATIC_URL = '/static/'.
Then I have 'django.contrib.staticfiles' under INSTALLED_APPS in settings.


RE: [Django] css file is not applying to the page - menator01 - May-09-2020

If your on an apache2 web server, you may need to setup an alias for the static folder.
Or you may need to do the collect static command. I don't remember the command.
Here is how mine is setup. The static folder resides in the django root folder.
I did not see tags for and code other than python.
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{% block title %}{% endblock title %}</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <link rel="stylesheet" href="{% static 'css/homepages/home.css' %}">
        <link href="https://fonts.googleapis.com/css?family=Peralta&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="{% static 'css/all.css' %}">
    </head>