Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Where to add css files within django project

$
0
0

I'm building a To Do list in Django by following a tutorial,

I'm trying to make seperate CSS file instead of directly writing it within HTML file, However i'm recieving 404 error.

Below is directory structure

├─ base/│├─ templates/││└─ base/││├─ login.html││├─ main.html││├─ register.html││├─ style.css││├─ task_confirm_delete.html││├─ task_form.html││├─ task_list.html││└─ task.html│├─ __init__.py│├─ admin.py│├─ apps.py│├─ models.py│├─ tests.py│├─ urls.py│└─ views.py├─ simpletodo/│├─ __init__.py│├─ asgi.py│├─ settings.py│├─ urls.py│└─ wsgi.py├─ venv/├─ db.sqlite3└─ manage.py

Below are files where I'm strying to include css file

  1. main.html
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>To Do List</title><link rel="stylesheet" href="style.css"></head><body><div class="container"><!-- elements from other pages will go here -->        {% block content %}        {% endblock content %}</div></body>
  1. task_list.html
{% extends 'base/main.html' %} {% block content %}    ** some code **{% endblock content %}

Only static i've declared is as below

  1. settings.py
STATIC_URL = 'static/'

Follow up - How do I include other files like scripts in a seperate files as well ?

Following other answers i've triedmaking a static folder and include css file in that

base/│├── static/│└── base/│└── style.css│├── templates/│└── base/
STATICFILES_DIRS = [    os.path.join(BASE_DIR, 'base/static'),]

Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>