Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do we have to deploy staticfiles folder to heroku?

Tags:

django

heroku

When I follow some tutorial on the web, there is staticfiles folder included in .gitignore file. Although when I included it in .gitignore file it is deployed to heroku server. I can see that folder in my main directory. Then why is it included in .gitignore file?

like image 294
Maksim Kevin Avatar asked Oct 12 '25 15:10

Maksim Kevin


2 Answers

you dont commit your static folder to version control, you normally make another site-static folder for your css, js and img. it is simply because there are many other static files coming from e.g. django admin which lands into static folder if you do collectstatic. after collectstatic you will see many other static files of django apps / another installed apps which makes it hard to manage your own static files. thats why you need to ignore static folder and work locally in your site-static folder

I can see that folder in my main directory: that folder came from collectstatic command which collects all static files into static folder.

dont forget to make:

STATICFILES_DIRS = (
    os.path.join(PROJECT_PATH, 'site-static'),
)
like image 151
doniyor Avatar answered Oct 14 '25 03:10

doniyor


Heroku looks for all folders named static in your project and copies all asset files from these folders to staticfiles on heroku. You don't need to manually create and push the staticfiles folder to heroku. It is created automatically.

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
like image 38
Emmanuel Osimosu Avatar answered Oct 14 '25 04:10

Emmanuel Osimosu