How to access Heroku config variables inside Django settings - django

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')

Related

Django + Heroku deployment

I tried several times now to deploy my Heroku application but I always receive the attached error message. After adding DISABLE_COLLECTSTATIC=1 it works and I can remove it after. But it never works when it's enabled which it should be. Here a picture of my folder structure if it's needed https://drive.google.com/file/d/11L8jpFzYfDYT3Ob4G-soaGhL0pgU24iZ/view?usp=sharing
! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
Detected buildpacks: Python,Node.js
See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Python app detected
-----> Installing python-3.6.6
-----> Installing pip
-----> Installing dependencies with Pipenv 2018.5.18…
Installing dependencies from Pipfile.lock (d438cb)…
-----> Installing SQLite3
-----> $ python manage.py collectstatic --noinput
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 371, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, 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 112, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
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/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 114, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 315, in add_to_class
value.contribute_to_class(cls, name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 205, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 199, in __getitem__
self.ensure_defaults(alias)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 171, in ensure_defaults
conn.setdefault('ATOMIC_REQUESTS', False)
AttributeError: 'NoneType' object has no attribute 'setdefault'
! 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
It might be unrelated to collectstatic. Similar exception was described here: python error AttributeError: 'str' object has no attribute 'setdefault'.
I'd suggest checking your DATABASES setting in your settings.py. Check out django-heroku (https://github.com/heroku/django-heroku) if you're not using it already and just use this in your settings:
import django_heroku
django_heroku.settings(locals())

Deploy django cookiecutter template on Heroku

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.

Django DB Connection with mangoDB using mangoengine gives me error?

I am getting the connection error while connecting mangodb through django using mongoengine
I have included following things to settings.
mongoengine.connect('zaya', username='admin', password='secret')
# Mongo DB Sessions
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
Also I have created db with name zaya , user admin and password secrete
To create this I have followed below link:
http://petrkout.com/programming/setting-up-django-with-mongodb/
Error Stack Trace:
packages/pymongo/client_options.py", line 108, in <listcomp>
options = dict([validate(opt, val) for opt, val in iteritems(options)])
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/pymongo/common.py", line 425, in validate
value = validator(option, value)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/pymongo/common.py", line 249, in validate_read_preference
raise TypeError("%r is not a read preference." % (value,))
TypeError: False is not a read preference.
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 "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/core/management/__init__.py", line 338,
execute_from_command_line
utility.execute()
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/neha/MyProjects/StudentAssessment/src/settings.py", line 103, in <module>
mongoengine.connect('zaya', username='admin', password='secret')
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/mongoengine/connection.py", line 164, in connect
return get_connection(alias)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/mongoengine/connection.py", line 126, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
False is not a read preference.
pip uninstall pymongo
pip install pymongo==2.8
It seems you got this issue:
https://github.com/MongoEngine/mongoengine/issues/935
Try downgrading to pymongo 2.8
pip uninstall pymongo
pip install pymongo==2.8

S3BotoStorage in python 3

I've setup my Django project to store static and user-uploaded files into Amazon S3. In order to accomplish that, I've followed the example found herer https://ashokfernandez.wordpress.com/2014/03/11/deploying-a-django-app-to-amazon-aws-with-nginx-gunicorn-git/:
prod.py
INSTALLED_APPS += ('storages',)
AWS_STORAGE_BUCKET_NAME = "project"
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL
but when I try to run manage.py collectstatic -v 0 --noinput I get this error:
Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 7, in <module>
from cStringIO import StringIO
ImportError: No module named 'cStringIO'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/webapps/project/manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 238, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 42, in load_command_class
return module.Command()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 58, in __init__
self.storage.path('')
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/functional.py", line 224, in inner
self._setup()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 391, in _setup
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/storage.py", line 303, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 9, in <module>
from StringIO import StringIO # noqa
ImportError: No module named 'StringIO'
It seems the lib django-storages==1.1.8 doesn't support Python3 yet, and that's why I'm getting that error.
My question is: How can I solve this problem? Is there any similar lib to replace django-storages?
I'm using django 1.7.1 and Python3.
I just have solved my own problem with this new repo:
https://github.com/jschneier/django-storages-redux/issues/6
This thread have a complete solution using this new django-storages

django not able to find git

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?