I am trying to deploy a web on Heroku.
When I run heroku run python manage.py migrate I will get some errors:
django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable
I read the documentation on Cookiecutter, the document said I have to specify these values. But it didn't tell me what's the purpose and the method. I am wondering do I really have to specify all this values?
DJANGO_AWS_ACCESS_KEY_ID
DJANGO_AWS_SECRET_ACCESS_KEY
DJANGO_AWS_STORAGE_BUCKET_NAME
DJANGO_SENTRY_DSN
DJANGO_SENTRY_CLIENT
DJANGO_SENTRY_LOG_LEVEL
DJANGO_MAILGUN_API_KEY
DJANGO_MAILGUN_SERVER_NAME
Logs:
$ heroku logs --app glacial-forest-93266 --dyno run.9155
2017-02-23T03:28:44.634830+00:00 heroku[run.9155]: Starting process with command `python manage.py migrate`
2017-02-23T03:28:45.292164+00:00 heroku[run.9155]: State changed from starting to up
2017-02-23T03:28:47.487454+00:00 heroku[run.9155]: Process exited with status 1
2017-02-23T03:28:47.336279+00:00 app[run.9155]: /app/.heroku/python/lib/python3.5/site-packages/environ/environ.py:608: UserWarning: /app/co
nfig/settings/.env doesn't exist - if you're not configuring your environment separately, create one.
2017-02-23T03:28:47.359554+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.359557+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 264, in ge
t_value
2017-02-23T03:28:47.336297+00:00 app[run.9155]: "environment separately, create one." % env_file)
2017-02-23T03:28:47.359787+00:00 app[run.9155]: value = self.ENVIRON[var]
2017-02-23T03:28:47.359791+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/os.py", line 683, in __getitem__
2017-02-23T03:28:47.360099+00:00 app[run.9155]: raise KeyError(key) from None
2017-02-23T03:28:47.360103+00:00 app[run.9155]: KeyError: 'DJANGO_SENTRY_DSN'
2017-02-23T03:28:47.360105+00:00 app[run.9155]:
2017-02-23T03:28:47.360106+00:00 app[run.9155]: During handling of the above exception, another exception occurred:
2017-02-23T03:28:47.360107+00:00 app[run.9155]:
2017-02-23T03:28:47.360109+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.360130+00:00 app[run.9155]: File "manage.py", line 23, in <module>
2017-02-23T03:28:47.360228+00:00 app[run.9155]: execute_from_command_line(sys.argv)
2017-02-23T03:28:47.360246+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
line 367, in execute_from_command_line
2017-02-23T03:28:47.360425+00:00 app[run.9155]: utility.execute()
2017-02-23T03:28:47.360427+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
line 359, in execute
2017-02-23T03:28:47.360606+00:00 app[run.9155]: self.fetch_command(subcommand).run_from_argv(self.argv)
2017-02-23T03:28:47.360609+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
line 208, in fetch_command
2017-02-23T03:28:47.360739+00:00 app[run.9155]: klass = load_command_class(app_name, subcommand)
2017-02-23T03:28:47.360740+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
line 40, in load_command_class
2017-02-23T03:28:47.360838+00:00 app[run.9155]: module = import_module('%s.management.commands.%s' % (app_name, name))
2017-02-23T03:28:47.360960+00:00 app[run.9155]: return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.360840+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module
2017-02-23T03:28:47.360962+00:00 app[run.9155]: File "<frozen importlib._bootstrap>", line 986, in _gcd_import
2017-02-23T03:28:47.361192+00:00 app[run.9155]: File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
2017-02-23T03:28:47.361105+00:00 app[run.9155]: File "<frozen importlib._bootstrap>", line 969, in _find_and_load
2017-02-23T03:28:47.361278+00:00 app[run.9155]: File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
2017-02-23T03:28:47.361364+00:00 app[run.9155]: File "<frozen importlib._bootstrap_external>", line 662, in exec_module
2017-02-23T03:28:47.361554+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migr
ate.py", line 15, in <module>
2017-02-23T03:28:47.361466+00:00 app[run.9155]: File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
2017-02-23T03:28:47.361645+00:00 app[run.9155]: from django.db.migrations.autodetector import MigrationAutodetector
2017-02-23T03:28:47.361645+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/autodetector.py
", line 13, in <module>
2017-02-23T03:28:47.361739+00:00 app[run.9155]: from django.db.migrations.questioner import MigrationQuestioner
2017-02-23T03:28:47.361740+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/questioner.py",
line 12, in <module>
2017-02-23T03:28:47.361832+00:00 app[run.9155]: from .loader import MigrationLoader
2017-02-23T03:28:47.361833+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/loader.py", lin
e 10, in <module>
2017-02-23T03:28:47.361923+00:00 app[run.9155]: from django.db.migrations.recorder import MigrationRecorder
2017-02-23T03:28:47.361924+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 12, in <module>
2017-02-23T03:28:47.362014+00:00 app[run.9155]: class MigrationRecorder(object):
2017-02-23T03:28:47.362015+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 26, in MigrationRecorder
2017-02-23T03:28:47.362109+00:00 app[run.9155]: class Migration(models.Model):
2017-02-23T03:28:47.362110+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 27, in Migration
2017-02-23T03:28:47.362206+00:00 app[run.9155]: app = models.CharField(max_length=255)
2017-02-23T03:28:47.362206+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1043, in __init__
2017-02-23T03:28:47.362557+00:00 app[run.9155]: super(CharField, self).__init__(*args, **kwargs)
2017-02-23T03:28:47.362558+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 166, in __init__
2017-02-23T03:28:47.362682+00:00 app[run.9155]: self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
2017-02-23T03:28:47.362683+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 53, i
n __getattr__
2017-02-23T03:28:47.362790+00:00 app[run.9155]: self._setup(name)
2017-02-23T03:28:47.362791+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 41, i
n _setup
2017-02-23T03:28:47.362927+00:00 app[run.9155]: self._wrapped = Settings(settings_module)
2017-02-23T03:28:47.362929+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 97, i
n __init__
2017-02-23T03:28:47.363042+00:00 app[run.9155]: mod = importlib.import_module(self.SETTINGS_MODULE)
2017-02-23T03:28:47.363043+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module
2017-02-23T03:28:47.363153+00:00 app[run.9155]: return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.363154+00:00 app[run.9155]: File "/app/config/settings/production.py", line 161, in <module>
2017-02-23T03:28:47.363279+00:00 app[run.9155]: SENTRY_DSN = env('DJANGO_SENTRY_DSN')
2017-02-23T03:28:47.363394+00:00 app[run.9155]: return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
2017-02-23T03:28:47.363395+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 268, in ge
t_value
2017-02-23T03:28:47.363558+00:00 app[run.9155]: raise ImproperlyConfigured(error_msg)
2017-02-23T03:28:47.363281+00:00 app[run.9155]: File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 126, in __
call__
2017-02-23T03:28:47.363560+00:00 app[run.9155]: django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable
2017-02-23T03:28:47.501504+00:00 heroku[run.9155]: State changed from up to complete
You could check all the necessary settings here: http://cookiecutter-django.readthedocs.io/en/latest/settings.html
Generally, you could just define a blank value for it like:
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=''
Specifically, you can leave the AWS values blank if you won't upload to S3, you can leave SENTRY values blank if you disable sentry, and you can leave MAILGUN app if you disable mailgun.
You are using the production.py settings inside /config/settings by running this line:
heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production'
Either make a separate settings file for heroku not having SENTRY and other services, else just uncomment lines initializing those services.
Also you'll want to keep the /media and /static local if you're not using aws.
Related
I am trying to push my code on Heroku, I have hidden my secret key using environ package but now Heroku is not able to access it since I have ignored my .env file using gitignore, I have read about config vars in Heroku but I am having trouble understanding how do I make Django access those values
import os
import environ
# from .secret import key
env = environ.Env()
environ.Env.read_env()
SECRET_KEY = env('KEY',default=env('SECRET_KEY'))
updated code
In the log, it is giving me error like this
warnings.warn(
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 277, in get_value
value = self.ENVIRON[var]
File "/app/.heroku/python/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'SECRET_KEY'
During handling of the above exception, another exception occurred:
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 "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 244, in fetch_command
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python3.8/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 "/tmp/build_067d1d45/food_deliveryapp/settings.py", line 22, in <module>
SECRET_KEY = os.environ.get('KEY',env('SECRET_KEY'))
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 127, in __call__
return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
File "/app/.heroku/python/lib/python3.8/site-packages/environ/environ.py", line 281, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
! 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
For every variable in .env create a Config Var, make sure names are UPPERCASE.
In your code you can access them via environ (map with all env variables):
my_secret = (os.environ.get("MY_SECRET", 'dev default value')
I am not fluent in Django,been doing for over 3 months now, BUT I have never seen such error. Please if someone can help me out of this situation.
I am doing the short_url module, bt befoe that i have pip installed shorturls , then i created an app shorturls. Again , i have to delte the app shorturls. And after that i have been facing this issue.
Following is my full traceback of the error:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\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 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\shorturls\templatetags\shorturl.py", line 5, in <module>
from django.core import urlresolvers
ImportError: cannot import name 'urlresolvers' from 'django.core' (C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\__init__.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\blink\myblink\manage.py", line 23, in <module>
main()
File "C:\blink\myblink\manage.py", line 19, in main
execute_from_command_line(sys.argv)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
super().execute(*args, **options)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 96, in handle
self.run(**options)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 103, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 637, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 622, in start_django
reloader.run(django_main_thread)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 327, in run
autoreload_started.send(sender=self)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\dispatch\dispatcher.py", line 180, in send
return [
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\dispatch\dispatcher.py", line 181, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\autoreload.py", line 41, in watch_for_template_changes
for directory in get_template_directories():
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\autoreload.py", line 14, in get_template_directories
for backend in engines.all():
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 90, in all
return [self[alias] for alias in self]
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 123, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'shorturls.templatetags.shorturl': cannot
import name 'urlresolvers' from 'django.core' (C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\__init__.py)
I'm new and trying to follow this tutorial:
https://www.youtube.com/watch?v=_uQrJ0TkZlc
from 05:00:00 I follow him just like he doing, then at 05:05:04 when he run the server it's work fine for him, but for me is not.
This is exactly my steps....
After Install django like this:
pip install django
I write this:
django-admin startproject pyshop .
so far all good, no error, then I try to run the server like this:
python manage.py runserver
But then I get a big error:
Exception ignored in thread started by: <function check_errors.<locals>.wrapper at 0x000001D36DA79AF0>
Traceback (most recent call last):
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\anaconda3\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 "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\models\base.py", line 304, in add_to_class
value.contribute_to_class(cls, name)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\utils.py", line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\User\OneDrive\Programing Code\Python\PyShop\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 10, in <module>
from sqlite3 import dbapi2 as Database
File "C:\Users\anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.
Help :(
Try by downloading the sqlite3 dll (find version that supports your system)
And put it into the folder: C:\Users\YOURUSER\Anaconda3\DLLs
Install python3 and then run python3 manage.py runserver
Suppose you're not using Anaconda, you can download sqlite3 dll and add it to your system32 C:\Windows\System32 if you're using windows that is
I have the following structure in a django project.
I have a providers.py file in which:
from django.conf import settings
from project.utils.firewalls import fw
In providers I need to get some vars defined in settings.
Then in firewalls.py, I have:
from django.conf import settings
Also in firewalls.py, I do have some code which needs to get a variable that is defined in settings.
When I try to do:
python manage.py --settings=project.settings.local it will complain about not defining SECRET_KEY, although it is defined.
It has to do with the fact that I am importing django.conf.settings in both files.
How can I avoid that ?
For the moment I've hardcoded the value of the var in the firewalls.py, but I would like to avoid that.
Edit:
Add Stacktrack:
➤ python project/manage.py runserver --settings=project.settings.local
Traceback (most recent call last):
File "project/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/bsabin/Projects/repo/venv/lib64/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 "/home/bsabin/Projects/repo/project/project/settings/local.py", line 1, in <module>
from .base import *
File "/home/bsabin/Projects/repo/project/project/settings/base.py", line 21, in <module>
from project.utils.providers import AProvider, BProvider, CProvider
File "/home/bsabin/Projects/repo/project/project/utils/providers.py", line 6, in <module>
from project.utils.firewalls import fw
File "/home/bsabin/Projects/repo/project/project/utils/firewalls.py", line 29, in <module>
fw = get_firewall_instance()
File "/home/bsabin/Projects/repo/project/project/utils/firewalls.py", line 11, in get_firewall_instance
token = settings.DO_TOKEN.get('token')
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/bsabin/Projects/repo/venv/lib/python3.7/site-packages/django/conf/__init__.py", line 126, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I am assuming the problem you are facing is that you are using a function in a different file to pull some configuration data in settings, and inside that file you are importing the settings as well. In ideal case, it should trigger circular dependency error. But as django.conf.settings is lazy, it will raise Improper Configuration Error.
If you need some variables for configuration, why don't you pass the variable to the function directly. For example:
# in settings:
from project.utils.providers import AProvider, BProvider, CProvider
SOME_VARIABLE = AProvider(token="Your Token")
Then inside providers
class AProvider(...):
def __init__(self, *args, **kwargs):
token = kwargs.get('token')
# rest of the code
# somewhere in the code
fw = get_firewall_instance(self.token)
In firewall.py:
def get_firewall_instance(token_from_settings):
token = token_from_settings
I'm trying to get Django development started on my Windows 7 partition and I'm finding that whenever I run a Django command I get:
'git' is not recognized as an internal or external command,
operable program or batch file.
Often 3-4 times in a row but then the command seems to execute fine. While it doesn't seem to be affecting the execution of the commands, I don't like having errors thrown every time I do something, makes me nervous (and there's very possibly something I'm missing that's going wrong). I tried adding git to my environment variables but it didn't seem to work, here is the current PATH value.
;C:\Chocolatey\bin;C:\tools\mysql\current\bin;C:\Program Files (x86)\Git\bin
Any additional suggestions to try are welcome. I'm using Windows 7 and the most recent version of Python, Django, and Git (just downloaded them today).
EDIT: I ran the commands again in response to some of your comments (thanks for those btw). Here's the output to python manage.py runserver
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 14, in
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 416, in execute_from_command_line
utility.execute()
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 408, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 286, in execute
translation.activate('en-us')
File "C:\Python33\lib\site-packages\django\utils\translation\__init__.py", line 142, in activate
return _trans.activate(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 218, in activate
_active.value = translation(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 201, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 183, in _fetch
app = import_module(appname)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 870, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\Python33\lib\site-packages\django\contrib\admin\__init__.py", line 7, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\auth\forms.py", line 16, in <module>
from django.contrib.auth.models import User
File "C:\Python33\lib\site-packages\django\contrib\auth\models.py", line 40, in <module>
class Permission(models.Model):
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 291, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python33\lib\site-packages\django\db\models\options.py", line 141, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python33\lib\site-packages\django\db\__init__.py", line 39, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python33\lib\site-packages\django\db\utils.py", line 192, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python33\lib\site-packages\django\db\utils.py", line 107, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
And here's the output to python manage.py syncdb
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 14, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 416, in execute_from_command_line
utility.execute()
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 408, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 286, in execute
translation.activate('en-us')
File "C:\Python33\lib\site-packages\django\utils\translation\__init__.py", line 142, in activate
return _trans.activate(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 218, in activate
_active.value = translation(language)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 201, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python33\lib\site-packages\django\utils\translation\trans_real.py", line 183, in _fetch
app = import_module(appname)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 870, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\Python33\lib\site-packages\django\contrib\admin\__init__.py", line 7, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python33\lib\site-packages\django\contrib\auth\forms.py", line 16, in <module>
from django.contrib.auth.models import User
File "C:\Python33\lib\site-packages\django\contrib\auth\models.py", line 40, in <module>
class Permission(models.Model):
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python33\lib\site-packages\django\db\models\base.py", line 291, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python33\lib\site-packages\django\db\models\options.py", line 141, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python33\lib\site-packages\django\db\__init__.py", line 39, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python33\lib\site-packages\django\db\utils.py", line 192, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python33\lib\site-packages\django\db\utils.py", line 107, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Seems to be a result of missing MySQLdb. Does anyone have a link to this module? I can't find anything on Pypi called this exactly, I'm not sure which one it's looking for.
is it possible that you overwrote your "manage.py" with something which tries to start git? Your manage.py should look like this:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Or do you have a "git" commant in your settings.py?
EDIT after your error logs:
Did you install the MySQL-python package (see docs at https://docs.djangoproject.com/en/dev/topics/install/#get-your-database-running) AND MySQLdb (see https://docs.djangoproject.com/en/dev/ref/databases/#mysqldb)? Both are required when using MySQL.
If yes, do you get the same results when switching to a sqlite database?