Search code examples
pythoncssdjangopythonanywhere

Css file not loading on Python Anywhere


I have recently begun making a Django project on PythonAnyhwere.

I have followed the entire tutorial provided by Django for including static files on the project. I have observed the programs work fine on a site with http, but does not work on a site with https.

What could be the reasons and how can I overcome this problem?

Edit : The site is working now, apparently, but I would still like an explanation as to why it WAS working differently, if anyone can provide. Site on Https Site on http


Solution

  • to load your CSS files (or totally static files), you need to follow the steps below:

    1- inside settings.py

    STATIC_URL = '/static/'
    
    STATIC_ROOT=os.path.join(BASE_DIR,'static')
    
    MEDIA_ROOT=os.path.join(BASE_DIR,'media')
    
    MEDIA_URL='/media/'
    

    2-collect static files using bash console

    python manage.py collectstatic
    

    3-you need to enter the Static files directory inside the web tab

    check the image below

    static files python anywhere

    4- reload your web app