101👍
I just updated to Django 1.10 today and had the exact same problem.
Your static settings are identical to mine as well.
This worked for me, run the following commands:
-
disable the collectstatic during a deploy
heroku config:set DISABLE_COLLECTSTATIC=1
-
deploy
git push heroku master
-
run migrations (django 1.10 added at least one)
heroku run python manage.py migrate
-
run collectstatic using bower
heroku run 'bower install --config.interactive=false;grunt prep;python manage.py collectstatic --noinput'
-
enable collecstatic for future deploys
heroku config:unset DISABLE_COLLECTSTATIC
-
try it on your own (optional)
heroku run python manage.py collectstatic
future deploys should work as normal from now on
42👍
You have STATICFILES_DIRS
configured to expect a static
directory in the same directory as your settings.py
file, so make sure it’s there not somewhere else.
Also, do you have any files in that static
directory? If you don’t then git won’t track it and so although it exists locally it won’t exist in git. The usual solution to this is to create an empty file called .keep
in the directory which will ensure that git tracks it. But once you have some static files in this directory then it won’t be a problem anymore.
- [Django]-"Too many values to unpack" Exception
- [Django]-Disable session creation in Django
- [Django]-Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
24👍
DO NOT disable collectstatic
on heroku with heroku config:set DISABLE_COLLECTSTATIC=1
. This will just hide the error and not make your app healthy.
Instead, it’s better to understand why the collectstatic command fails because it means something is not right with your settings.
Step 1
Run locally both commands:
python manage.py collectstatic
python manage.py test
You should see one or more error messages. Most of the time, it’s a missing variable (for ex: STATIC_ROOT
) you must add to your project settings.py
file.
It’s necessary to add the test
command because some collectstatic
related issues will only surface with test
, such as this one
Step 2
Once you’ve fixed all the error messages locally, push again to heroku.
Troubleshooting
Remember you can also run commands directly in your heroku VM.
If you cannot reproduce locally, run the collecstatic command in heroku and check what’s going on directly in your production environment:
python manage.py collectstatic --dry-run --noinput
(Same goes for heroku console obviously)
- [Django]-Getting Values of QuerySet in Django
- [Django]-Django DB Settings 'Improperly Configured' Error
- [Django]-Django – "no module named django.core.management"
7👍
Run python manage.py collectstatic
locally and fix any errors. In my case there were reference errors that prevented that command from running successfully.
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-AbstractUser vs AbstractBaseUser in Django?
- [Django]-Alowing 'fuzzy' translations in django pages?
6👍
if you use django-heroku library
maybe you forget for put this setting in the bottom of line text settings.py for can possible read all config parameters
import django_heroku
django_heroku.settings(locals())
as like as the documentation:
Usage of Django-Heroku
In settings.py
, at the very bottom::
…
# Configure Django App for Heroku.
import django_heroku
django_heroku.settings(locals())
This will automatically configure DATABASE_URL
, ALLOWED_HOSTS
, WhiteNoise (for static assets), Logging, and Heroku CI for your application.
p.s: sorry for my bad english
- [Django]-Is it secure to store passwords as environment variables (rather than as plain text) in config files?
- [Django]-Django values_list vs values
- [Django]-Name '_' is not defined
5👍
This worked for me:
step 1 – heroku config:set DISABLE_COLLECTSTATIC=1
step 2 – git push heroku master
- [Django]-Django class-based view: How do I pass additional parameters to the as_view method?
- [Django]-'staticfiles' is not a valid tag library: Template library staticfiles not found
- [Django]-Is there any difference between django.conf.settings and import settings?
5👍
-
This error has occurred because you do not have staticfiles in
your Project’s Root Directory. -
Don’t worry. The solution is SIMPLE.
-
You only need TWO STEPS.
Step 1: Open your settings.py file and write
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_ROOT = BASE_DIR / 'staticfiles'
Step 2: Run below given command in terminal in your Project’s root directory.
(If you are using any Virtual environment for Django Project then go inside your Virtual environment and then go into your Project’s root directory and then run below given command.)
python manage.py collectstatic
Congrats : Your Problem is Solved.
Now, you can COMMIT and PUSH your "changes" so that it is reflected in your Repository and then you are good to go.
- [Django]-Can you give a Django app a verbose name for use throughout the admin?
- [Django]-Django Generic Views using decorator login_required
- [Django]-Update all models at once in Django
4👍
I face same problem..
Follow this step
- heroku config:set
DISABLE_COLLECTSTATIC=1
git push heroku master
python manage.py collectstatic
python manage.py test
- If any error occurred after running test..check your
STATIC_ROOT is correct like this ==>STATIC_ROOT = os.path.join(BASE_DIR, 'static')
. - After run collectstatic command check all static files are
store in static directory for your root dir. level(manage.py
dir. level)… heroku run python manage.py collectstatic
.heroku run python manage.py migrate
heroku config:unset DISABLE_COLLECTSTATIC
(for future use).
- [Django]-What is a NoReverseMatch error, and how do I fix it?
- [Django]-How to update an existing Conda environment with a .yml file
- [Django]-Django order_by query set, ascending and descending
2👍
Heroku had made a document with suggestions on how to handle this https://devcenter.heroku.com/articles/django-assets
add to settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
make a directory in the root of your project called staticfiles
, put a favicon or something in there, just make sure git tracks it. Then the collectstatic command should finish on heroku.
- [Django]-What is the right way to validate if an object exists in a django view without returning 404?
- [Django]-Dynamic choices field in Django Models
- [Django]-Get Timezone from City in Python/Django
1👍
Ran to that issue after trying to deploy an app again. The problem got cured after I specified these commands:
$ heroku config:set SECRET_KEY="*secret_key*"
$ heroku config:set DEBUG_VALUE="True"
$ heroku config:set EMAIL_USER="*user-email*"
$ heroku config:set EMAIL_PASS="*pass*"
These variables in settings.py were invoked with local environment variables,
which heroku didn’t have on its environment, hence the error.
- [Django]-Tying in to Django Admin's Model History
- [Django]-Class Based Views VS Function Based Views
- [Django]-RuntimeWarning: DateTimeField received a naive datetime
0👍
It seems to me that it’s having problems creating that blogproject/static
folder. I see you have a static folder inside your blog app, but it should be up one level in your blogproject folder.
Try creating a static
folder inside your blogproject
folder and that error should go away.
- [Django]-How do you log server errors on django sites
- [Django]-Resize fields in Django Admin
- [Django]-How do I include image files in Django templates?
0👍
Today, not all of the requirements came in properly with $ pipenv install django
from the heroku-django-template and $ pip install -r requirements.txt
.
The latest version of the template includes a /static
folder with a humans.txt
, so the previous solution is likely not the proplem
Try running $ pipenv install whitenoise
and then $ pip freeze > requirements.txt
.
If that works, I would recommend $ pip install psycopg2 --ignore-installed
and $ pip freeze > requirements.txt
as well, otherwise you will similarly have problems migrating.
- [Django]-Python Asyncio in Django View
- [Django]-Why doesn't django's model.save() call full_clean()?
- [Django]-Django queries: how to filter objects to exclude id which is in a list?
0👍
I faced the same issue while deploying my app. I realized I had updated my pip version, installed few plugins but forgot to create a fresh requirements.txt
file.
Run pip freeze > requirements.txt
in your terminal
Run python manage.py collectstatic
Now push the code to github and deploy to heroku server
Hope this helps if that is the case
- [Django]-Django check if a related object exists error: RelatedObjectDoesNotExist
- [Django]-Django: Get list of model fields?
- [Django]-How to do SELECT MAX in Django?
0👍
insert this line of code to your setting.py file.
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
- [Django]-Checking for empty queryset in Django
- [Django]-Error: "dictionary update sequence element #0 has length 1; 2 is required" on Django 1.4
- [Django]-Django TextField and CharField is stripping spaces and blank lines
0👍
In my case was an error almost like described above, after push-ing that resulted in errors, I set the SECRET_KEY "heroku config:set SECRET_KEY='*************************'"
,
git push heroku main
(again)
,
heroku run python manage.py migrate
,
heroku run python manage.py createsuperuser
.. and everything
,
heroku open
and it worked 🙂
- [Django]-Django – Circular model import issue
- [Django]-DatabaseError: current transaction is aborted, commands ignored until end of transaction block?
- [Django]-Django CSRF check failing with an Ajax POST request
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
- [Django]-Redirect to Next after login in Django
- [Django]-Django – get() returned more than one topic
- [Django]-Django-Forms with json fields
- [Django]-How to make Django serve static files with Gunicorn?
- [Django]-POST jQuery array to Django
0👍
This problem occurs because Heroku tries to run manage.py.
While executing manage.py
we have to write like
python manage.py 'some_command'
But Heroku tries it as
python manage.py --noinput
So in this case we can make changes to our manage.py file:
Initialy it looks like this:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'your_project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv) # just put this in try block
if __name__ == '__main__':
main()
So we change our main.py to:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'your_project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
try:
execute_from_command_line(sys.argv) # just put this in try block
except:
pass
if __name__ == '__main__':
main()
- [Django]-How can I set a default value for a field in a Django model?
- [Django]-How to delete project in django
- [Django]-Django select_for_update cannot be used outside of a transaction
0👍
If you used .env
files and python-decouple
you’ll have to define the environmental variables in Heroku app settings > Config Vars
. Otherwise collectstatic
won’t work.
- [Django]-Django south migration – Adding FULLTEXT indexes
- [Django]-How to set up custom middleware in Django?
- [Django]-How to access the user profile in a Django template?
0👍
After testing everything that was posted on this thread, here’s what worked for me:
- Keep the Heroku environment variable
DISABLE_COLLECTSTATIC
set to 0, as it won’t really solve the issue, but just mask it and mess with your site’s assets - When using django_heroku lib on the settings file, include the argument "staticfiles=False", like this:
django_heroku.settings(locals(), staticfiles=False)
- The STATIC_ROOT variable on settings.py should be set as
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
, being BASE_DIR set asBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
. This is described on Heroku’s django-assets doc - After doing all that, run a
python manage.py migrate
on Heroku CLI and you should see a message about assets downloaded.
Before making it to actually work, the collectstatic command python manage.py collectstatic
on Heroku CLI was giving a correct output, so be aware that you may get no errors with this command, but still have something wrong going on.
- [Django]-Class Based Views VS Function Based Views
- [Django]-How can I use Django permissions without defining a content type or model?
- [Django]-Celery parallel distributed task with multiprocessing
0👍
Well in my research about this error, I found out that by just adding.
DISABLE_COLLECTSTATIC = 1
in the env variables in Heroku resolved the error
- [Django]-Django filter on the basis of text length
- [Django]-How to force Django models to be released from memory
- [Django]-How do I get user IP address in Django?