1

Im making a 'learning website' along with the treehouse course and when I run my website server the GET for the CSS returns a 404 error, below I will provide the details I think will help you help me. Thank you for any help this is annoying for trying to learn Django. Ive looked everywhere and cannot find something to help me, I will happily give more info in the comments!

Here is my file structure:

~/PycharmProjects/learning_site
|--.idea
|--assets
|    |--css
|      |--layout.css
|--courses
|--learning_site
|--templates
db.sqlite2
manage.py

This is my static variables defined in the settings.py file.

STATIC_URL = '/static/'
STATICFIILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

This is my layout.html template where the css is called.

{% load static %}<!doctype html>
<html>
    <head>
        <title> {% block title %} {% endblock %}</title>
        <link rel = "stylesheet" href="{% static '/css/layout.css' %}"}>
    </head>
    <body>
    <div class="site-container">
    {% block content %}{% endblock content %}
    </div>
    </body>
</html>

This is the homepage where the CSS would be displayed.

{% extends "layout.html" %}

{% block title %} Well  hello there! {% endblock %}

{% block content %}
<h1>Welcome!</h1>
{% endblock %}
<a href="127.0.0.1/courses/"> Courses offered </a>

1 Answers1

0

Please check there is an extra } in yout <link> tag. Fix it:

<link rel = "stylesheet" href="{% static '/css/layout.css' %}">

and take a look in your STATIC_ROOT in settings.py and run pyhton manage.py collectstatic as well.

barii
  • 339
  • 3
  • 12
  • 1
    I fixed my error in the code, thank you! I do not know what to set STATIC_ROOT to, its not in my settings.py by default – Bryce Wellman Jul 02 '20 at 06:53
  • check this: https://stackoverflow.com/questions/8687927/difference-between-static-static-url-and-static-root-on-django – barii Jul 02 '20 at 06:55