Emm
Emm

Reputation: 2507

Django not loading css and JS

As the question implies, my django doesn't seem to be loading the js and css for my theme.

This is the structure of my project:

-->mysiteX
---->.idea
---->mysite
------->migrations
       __init__
       admin.py
       apps.py
       models.py
       test.py
       views.py
---->mysiteX
       __init__
       settings
       urls
       wsgi
----->venv
-------->Lib
---------->site-packages
----------->django
------------>contrib
------------->auth
-------------->templates
               index.html
--------------->static
---------------->js
---------------->css
---------------->img
---------------->fonts                
db.sqlite3
manage

This is what I have in my settings.py file

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, '/templates')
STATIC_URL = '/templates/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

I have tried changing my settings.py file to this effect

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/templates/static')

but still not getting the css and JS loaded. Here is a screenshot of my page screenshot

Upvotes: 1

Views: 100

Answers (2)

Josir
Josir

Reputation: 1644

The static path (css,html,js) and is not listed on path structure appended here. Where is it located? Assuming you forgot to add it, here is the debug steps:

1) Certify that you have a /static folder on BASE_DIR

2) You should run "python manage.py collectstatic"

3) If it didn't work, press F12 (or view source code) on your browser to see where the css location was rendered.

Upvotes: 0

Hamza Lachi
Hamza Lachi

Reputation: 1064

Change This Line:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

To This:

STATIC_ROOT = os.path.join(BASE_DIR, '/templates/static')

Upvotes: 1

Related Questions