roku config:set DISABLE_COLLECTSTATIC=1 Django - python

$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "/tmp/build_01f62511/manage.py", line 22, in <module>
main()
File "/tmp/build_01f62511/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 386, in execute
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 92, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/tmp/build_01f62511/main/settings.py", line 25, in <module>
SECRET_KEY = config("SECRET_KEY")
File "/app/.heroku/python/lib/python3.10/site-packages/decouple.py", line 243, in __call__
return self.config(*args, **kwargs)
File "/app/.heroku/python/lib/python3.10/site-packages/decouple.py", line 105, in __call__
return self.get(*args, **kwargs)
File "/app/.heroku/python/lib/python3.10/site-packages/decouple.py", line 90, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: SECRET_KEY not found. Declare it as envvar or define a default value.
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
HOW CAN I SOLVE THE PROBLEM?

Run this command in your terminal in the Root Dir of your project
heroku config:set SECRET_KEY=SAFSAFSDAFSDF0ASDFSD

Related

coverage using wrong python path, although venv is sourced

I am working on a Django project and trying to run the command coverage run --source='.' manage.py test myapp from the Django documentation. Somehow coverage uses a different python path than the virtual environment I am in (I guess that is the reason that the module is not found)
I get the following output:
(venv) username in ~/project on branch basket > coverage run --source='.' manage.py test myapp
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/base.py", line 322, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/base.py", line 296, in create_parser
self.add_arguments(parser)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/commands/test.py", line 44, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/test/utils.py", line 302, in get_runner
test_runner_class = test_runner_class or settings.TEST_RUNNER
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 83, in __getattr__
self._setup(name)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 177, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 14, in <module>
from decouple import config, Csv
ModuleNotFoundError: No module named 'decouple'
I am using venv from the regular python installation and checked my venv by importing a non-existent module in my settings.py:
from testmodule import test, which gives me the following output for the command python manage.py runserver
(venv) username in ~/project > python manage.py runserver
Traceback (most recent call last):
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super().execute(*args, **options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 16, in <module>
from testmodule import test
ModuleNotFoundError: No module named 'testmodule'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/username/project/manage.py", line 22, in <module>
main()
File "/Users/username/project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 367, in run_from_argv
connections.close_all()
File "/Users/username/project/venv/lib/python3.9/site-packages/django/db/utils.py", line 208, in close_all
for alias in self:
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 73, in __iter__
return iter(self.settings)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/db/utils.py", line 144, in configure_settings
databases = super().configure_settings(databases)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 16, in <module>
from testmodule import test
ModuleNotFoundError: No module named 'testmodule'
To me the problem doesn't seem related to django or the python-decouple module, but coverage not using the python path of my sourced venv. I tried to search the docs from coverage but couldn't identify what function or method is used when running coverage run can somebody help me out on where to look or how to identify the problem?
This seems to be a conflict with your global python packages.
As your log suggests, coverage is from /Users/username/.pyenv/versions/3.7.2/.
And you want to use the /Users/username/project/venv/lib/python3.9/.
There are 2 ways to do this, uninstall global coverage.
(venv) $ deactivate
$ pip3 uninstall coverage
$ source venv/bin/activate
(venv) $ python -m pip install coverage
Or if you plan on keeping global package you can try this.
(venv) $ python -m pip install coverage
(venv) $ python -m coverage
This will get the packages with respect to /Users/username/project/venv/lib/python3.9/

python manage.py runserver - Doesnt work in Django project

I started my first project with Django framework (Window platform).
When trying to run manage.py runserver, i received an Error.
Python version - 3.8.5 , Django version - 3.1
I am attaching the Error i received in the Terminal
(venv) C:\Users\shai.QIL\PycharmProjects\djangoProject>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\venv\lib\site-packages\django\core\management\__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\venv\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
self._setup(name)
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\venv\lib\site-packages\django\conf\__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\venv\lib\site-packages\django\conf\__init__.py", line 177, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\shai.QIL\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\shai.QIL\PycharmProjects\djangoProject\djangoProject\settings.py", line 57, in <module>
'DIRS': [os.path.join(BASE_DIR, 'templates')]
NameError: name 'os' is not defined
Thanks for your help!
You need to put import os in your settings.py

I am having issues uploading a Python project (using Django) to Heroku

I am trying to deploy a Python project to Heroku. When i press the "Deploy Branch" button on the Heroku website ... https://dashboard.heroku.com/apps//deploy/github i get this error.
Installing requirements with pip
$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blog'
Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
Push rejected, failed to compile Python app.
Push failed

Django can't migrate on Heroku

I have problem with migrating my database on Heroku trying to run heroku run python manage.py migrate. I always get this error:
(venv) E:\Studia\advise\promotion>heroku run python manage.py migrate
Running python manage.py migrate on ⬢ pro-motion... up, run.6349 (Free)
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 325, in execute
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/promotion/settings.py", line 27, in <module>
DEBUG = config('DEBUG', default=False, cast=bool)
File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 197, in __call__
return self.config(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 85, in __call__
return self.get(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 79, in get
return cast(value)
File "/app/.heroku/python/lib/python3.6/site-packages/decouple.py", line 50, in _cast_boolean
raise ValueError('Not a boolean: %s' % value)
ValueError: Not a boolean: True
Your screenshot shows a DEBUG environment variable whose value contains extra whitespace.
Depending on how you use that variable, the whitespace could easily caus problems. Delete that extra whitespace and see if that fixes things.
Also, you've partly revealed your SECRET_KEY and PostgreSQL credentials. Please change the SECRET_KEY and rotate your database credentials. Your current values are no longer secure.

Django 'python manage.py runserver' has from config import* error

I have an error when i use django.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/ghk/djangoprojects/lab-in-the-wild/labinthewild/settings.py", line 18, in <module>
from config import *
ModuleNotFoundError: No module named 'config'
If I command 'python manage.py runserver', it show this error.
As you said in your comments, you cloned this project from git.
Perhaps config is a local settings file you are meant to create yourself. Check the README and also check for a config example of some sorts

Categories