1

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

5
  • You got 'TATIC_URL' or 'STATIC_URL' in settings? Commented Dec 1, 2019 at 15:35
  • @MichaelStachura typo...I have STATIC_URL Commented Dec 1, 2019 at 15:40
  • I suppose it was typo mistake but it's always better to ask :) You got quite nested static files as I can see. I assume it is necessary due to project environment/requirements. Check what exactly your BASE_DIR and STATIC_ROOT are and then you will be able to fix it. At least (not reccomended) you can set STATIC_ROOT as an absolute path. Commented Dec 1, 2019 at 16:09
  • @MichaelStachura have been trying to do that but seem to be failing Commented Dec 1, 2019 at 17:25
  • Ok as i can see in comments below it's quite old Django version. Can you upgrade it to 2.2? Commented Dec 1, 2019 at 18:28

2 Answers 2

1

Change This Line:

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

To This:

STATIC_ROOT = os.path.join(BASE_DIR, '/templates/static')
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks, TATIC_URL was a typo, I actually have static_url
@Emm But in your structure there is no gradientboostMVP folder
sorry about that, have removed that, will update my question
version 1.11.26. Sorry do you mind elaborating what you mean by reset it to default do you mean the structure I had when I posted the question?
@Emm You Are Using Old Version Of Django If You Don't mind There is 2.2 version you can try because i don't know about old version of django! reset means try your default structure that you add in the question!
|
0

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.

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.