0

I am trying to deploy my Django 2.2 project with Keroku to see what it looks like during production, but it does not seem to work and I am finding it hard to debug the issue as there isn't solid instructions on static files settings.

To give an understanding of my files and file structure here is a tree:

.
├── apps
│   ├── __pycache__
│   ├── cart
│   │   ├── __pycache__
│   │   ├── migrations
│   │   │   └── __pycache__
│   │   ├── static
│   │   │   └── cart
│   │   │       ├── css
│   │   │       ├── img
│   │   │       ├── js
│   │   │       └── scss
│   │   └── templates
│   │       └── cart
│   ├── products
│   │   ├── __pycache__
│   │   ├── migrations
│   │   │   └── __pycache__
│   │   ├── static
│   │   │   └── products
│   │   │       ├── css
│   │   │       ├── img
│   │   │       ├── js
│   │   │       │   └── tools
│   │   │       └── scss
│   │   │           ├── mixins
│   │   │           ├── utilities
│   │   │           └── vendor
│   │   └── templates
│   │       └── products
│   └── users
│       ├── __pycache__
│       ├── migrations
│       │   └── __pycache__
│       ├── static
│       │   └── users
│       │       ├── css
│       │       ├── img
│       │       ├── js
│       │       └── scss
│       └── templates
│           └── users
├── docs
└── fancyfetish
    ├── __pycache__
    ├── settings
    │   └── __pycache__
    └── static
        └── fancyfetish

To make this easier to understand, basically I have a standard Django 2.2 set up, however my settings are split into three different types:

  • base.py
  • development.py
  • production.py

And are help with a directory called 'settings' within the main prject directory.

I have three 'apps' sp far, called:

  • products
  • cart
  • users

And they are stored within their own directory called 'apps'.

I am currently having issues deploying this project because of the static files. Currently, where statics are concerned, my settings for deployment are as follows:

STATIC_URL = '/static/'

STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ]

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

Firstly I am unsure as to whether this is correct. Secondly, whenever I push to heroku for deployment i get the same error traceback:

remote:        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_621274608c645b29c99cac8fc9e3a341/fancyfetish/static'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.

The full traceback is here:

Enumerating objects: 347, done.
Counting objects: 100% (347/347), done.
Delta compression using up to 8 threads
Compressing objects: 100% (325/325), done.
Writing objects: 100% (347/347), 569.74 KiB | 11.63 MiB/s, done.
Total 347 (delta 130), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing python-3.6.9
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting beautifulsoup4==4.8.1 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 1))
remote:          Downloading https://files.pythonhosted.org/packages/3b/c8/a55eb6ea11cd7e5ac4bacdf92bac4693b90d3ba79268be16527555e186f0/beautifulsoup4-4.
8.1-py3-none-any.whl (101kB)
remote:        Collecting Django==2.2.6 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 2))
remote:          Downloading https://files.pythonhosted.org/packages/b2/79/df0ffea7bf1e02c073c2633702c90f4384645c40a1dd09a308e02ef0c817/Django-2.2.6-py3-none-any.whl (7.5MB)
remote:        Collecting django-appconf==1.0.3 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 3))
remote:          Downloading https://files.pythonhosted.org/packages/f6/b3/fcec63afcf323581c4919f21e90ef8c8200034108a6a0ab47a6bf6a9327b/django_appconf-1.0.3-py2.py3-none-any.whl
remote:        Collecting django-bootstrap4==1.0.1 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 4))
remote:          Downloading https://files.pythonhosted.org/packages/3a/01/af39712da23fb3a1f1b41787dc150c255bd60f70324a6ec14be90d1576f2/django-bootstrap4-1.0.1.tar.gz (6.8MB)
remote:        Collecting django-compressor==2.3 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 5))
remote:          Downloading https://files.pythonhosted.org/packages/43/e2/50e21afd7e13b522f7d1a29cf0a6dd65e19835950dce3be3c5928e668846/django_compressor-2.3-py2.py3-none-any.whl (124kB)
remote:        Collecting django-libsass==0.7 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 6))
remote:          Downloading https://files.pythonhosted.org/packages/96/1a/0ebcb4e90b41f27d2b96adba01c62a590942686c6dbc7371ab89be044066/django-libsass-0.7.tar.gz
remote:        Collecting django-sass-processor==0.7.4 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 7))
remote:          Downloading https://files.pythonhosted.org/packages/6d/38/4d607938386244bc755dafa37e5dac6a222f6c3f1985d77b80c3e3712321/django-sass-processor-0.7.4.tar.gz
remote:        Collecting libsass==0.19.3 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 8))
remote:          Downloading https://files.pythonhosted.org/packages/88/51/1ea20121e4022d3f6ef7a87a0ed1063c83ba885cd22ae24516991a4e7b6b/libsass-0.19.3-cp36-cp36m-manylinux1_x86_64.whl (9.1MB)
remote:        Collecting mysql-connector-python==8.0.18 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 9))
remote:          Downloading https://files.pythonhosted.org/packages/f7/59/c2220c52d747da492f2aed108cdf99b640b88cf89dbbe2ea13a8c04201aa/mysql_connector_python-8.0.18-cp36-cp36m-manylinux1_x86_64.whl (16.1MB)
remote:        Collecting Pillow==6.2.1 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 10))
remote:          Downloading https://files.pythonhosted.org/packages/10/5c/0e94e689de2476c4c5e644a3bd223a1c1b9e2bdb7c510191750be74fa786/Pillow-6.2.1-cp36-cp36m-manylinux1_x86_64.whl (2.1MB)
remote:        Collecting protobuf==3.10.0 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 11))
remote:          Downloading https://files.pythonhosted.org/packages/a8/52/d8d2dbff74b8bf517c42db8d44c3f9ef6555e6f5d6caddfa3f207b9143df/protobuf-3.10.0-cp36-cp36m-manylinux1_x86_64.whl (1.3MB)
remote:        Collecting pytz==2019.3 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 12))
remote:          Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
remote:        Collecting rcssmin==1.0.6 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 13))
remote:          Downloading https://files.pythonhosted.org/packages/e2/5f/852be8aa80d1c24de9b030cdb6532bc7e7a1c8461554f6edbe14335ba890/rcssmin-1.0.6.tar.gz (582kB)
remote:        Collecting rjsmin==1.1.0 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 14))
remote:          Downloading https://files.pythonhosted.org/packages/62/ee/574b170bbe7a059314e7239305cb829379232a408901585019e012e71170/rjsmin-1.1.0-cp36-cp36m-manylinux1_x86_64.whl
remote:        Collecting six==1.12.0 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 15))
remote:          Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
remote:        Collecting soupsieve==1.9.5 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 16))
remote:          Downloading https://files.pythonhosted.org/packages/81/94/03c0f04471fc245d08d0a99f7946ac228ca98da4fa75796c507f61e688c2/soupsieve-1.9.5-py2.py3-none-any.whl
remote:        Collecting sqlparse==0.3.0 (from -r /tmp/build_621274608c645b29c99cac8fc9e3a341/requirements.txt (line 17))
remote:          Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
remote:        Installing collected packages: soupsieve, beautifulsoup4, sqlparse, pytz, Django, six, django-appconf, django-bootstrap4, rcssmin, rjsmin, django-compressor, libsass, django-libsass, django-sass-processor, protobuf, mysql-connector-python, Pillow
remote:          Running setup.py install for django-bootstrap4: started
remote:            Running setup.py install for django-bootstrap4: finished with status 'done'
remote:          Running setup.py install for rcssmin: started
remote:            Running setup.py install for rcssmin: finished with status 'done'
remote:          Running setup.py install for django-libsass: started
remote:            Running setup.py install for django-libsass: finished with status 'done'
remote:          Running setup.py install for django-sass-processor: started
remote:            Running setup.py install for django-sass-processor: finished with status 'done'
remote:        Successfully installed Django-2.2.6 Pillow-6.2.1 beautifulsoup4-4.8.1 django-appconf-1.0.3 django-bootstrap4-1.0.1 django-compressor-2.3 django-libsass-0.7 django-sass-processor-0.7.4 libsass-0.19.3 mysql-connector-python-8.0.18 protobuf-3.10.0 pytz-2019.3 rcssmin-1.0.6 rjsmin-1.1.0 six-1.12.0 soupsieve-1.9.5 sqlparse-0.3.0
remote: 
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 21, in <module>
remote:            main()
remote:          File "manage.py", line 17, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 105, in collect
remote:            for path, storage in finder.list(self.ignore_patterns):
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 131, in list
remote:            for path in utils.get_files(storage, ignore_patterns):
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
remote:            directories, files = storage.listdir(location)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 315, in listdir
remote:            for entry in os.scandir(path):
remote:        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_621274608c645b29c99cac8fc9e3a341/fancyfetish/static'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets

Obviously I feel this is mostly related to the 'File Not Found' part, but I am unsure as to how to resolve this.

I didn't have any static files within my main project directory, but added an empty static directory just incase it was searching there for statics that didn't exists, but it hasn't helped.

Thank you in advance for any help anyone can offer, especially in term of settings for static files

CThomas
  • 199
  • 1
  • 10

1 Answers1

1

This setting STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] tells Django to look for static files in a directory named static located at BASE_DIR

You can easily find your BASE_DIR by putting a print(BASE_DIR) in your settings.py and run it.

Then simply create a staic folder in that location and put all your static files there.

Also, there is no point creating static folder per app unless you would like to manage them that way.

bhaskarc
  • 9,269
  • 10
  • 65
  • 86