0

I'm having problems with my Django > css its not loading on the page for some reason am I missing something ?

I have attached snippets of my current code

Settings.py enter image description here

urls.py enter image description here

.html enter image description here

2

2 Answers 2

1

put in you'r setting.py

    INSTALLED_APPS = [
    'django.contrib.staticfiles', 
    ]
 STATIC_URL = '/static/'
STATIC_DIR = os.path.join(BASE_DIR,'static')

STATICFILES_DIRS = [

STATIC_DIR
]    

then create folder static/file.css(nameyourfile.css)

and then put in your ...html :

 <link rel="stylesheet" href= "{% static "file.css" %}">


    {% load sataticfiles %}

if you use version 3. put :

{% load static %}
Sign up to request clarification or add additional context in comments.

1 Comment

TY! I just had to remove the STATIC_URL and replace it with STATIC_DIR = os.path.join(BASE_DIR,'static') STATICFILES_DIRS = [ STATIC_DIR ]
0

You need to do a few more things to configure your static files.

First, you need to make sure django.contrib.staticfiles is included in your INSTALLED_APPS in your django settings.

Also, you need to add this line in your html document:

{% load static %}

I would follow this guide which explains static files in the django docs.

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.