Static files

Posted under » Django on 30 April 2021

Define where your static files reside at settings.py. You may also put your php files and it will run.

When you create it, it will be empty. Populate the static files folder with

$ python manage.py collectstatic

After running the command, you will see your static folder being populated.

Django itself doesn’t serve static (media) files, such as images, style sheets, or video. It leaves that job to whichever Web server you choose. So when you are using Apache, this is not enough and you will not see the static file being loaded. Unlike PHP, Python separates the static files from codes.

In your apache config file.

Alias /static/ /var/www/dblog/static/

    <Directory /var/www/dblog/static/>
        Order allow,deny
        Allow from all
    </Directory>

Reload Apache and you know everything is working well when you load your admin page, it is being formatted nicely.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data