I am trying to deploy django that now runs locally on ec2 ubuntu server. I got this while trying to run python mange.py runserver
i searched nothing seems to solve this
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 459, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/runserver.py", line 4, in <module>
from django.core.management.commands.runserver import BaseRunserverCommand
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 28, in <module>
from django.contrib.staticfiles import handlers
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 8, in <module>
from django.contrib.staticfiles.views import serve
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 15, in <module>
from django.contrib.staticfiles import finders
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 11, in <module>
from django.contrib.staticfiles.storage import AppStaticStorage
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/storage.py", line 10, in <module>
from django.core.cache import (get_cache, InvalidCacheBackendError,
File "/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py", line 187, in <module>
cache = get_cache(DEFAULT_CACHE_ALIAS)
File "/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py", line 172, in get_cache
backend, location, params = parse_backend_conf(backend, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py", line 125, in parse_backend_conf
backend = args.pop('BACKEND')
KeyError: 'BACKEND'
Set the backend in your Settings.py
Related
I started learning a Django tutorial , and when I want to run
python manage.py runserver
Here is the error message:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 6, in <module>
from .loader import MigrationLoader
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
class Migration(models.Model):
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 108, in __init__
"Please fix your settings." % setting)
django.core.exceptions.ImproperlyConfigured: The TEMPLATE_DIRS setting must be a tuple. Please fix your settings.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 6, in <module>
from .loader import MigrationLoader
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
class Migration(models.Model):
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/sarfraz/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 108, in __init__
"Please fix your settings." % setting)
django.core.exceptions.ImproperlyConfigured: The TEMPLATE_DIRS setting must be a tuple. Please fix your settings.
And there is the ligne in my project/settings.py
TEMPLATE_DIRS = (
"/home/sarfraz/django/crepes_bretonnes/templates/"
)
Hope it was clear.
Add a comma to the end of the value closed between parenthesis otherwise it is not a tuple:
TEMPLATE_DIRS = ( "/home/sarfraz/django/crepes_bretonnes/templates/", )
it should solve the issue. Hope that it helps.
I already installed Django Countries using pip install django_countries and still I'm getting an error of ImportError: cannot import name CountryField:
(simpli)Allens-MacBook-Air:~/Sites/augmify/simpli [master]$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/allenchun/.virtualenvs/simpli/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/allenchun/Sites/augmify/simpli/members/models/__init__.py", line 2, in <module>
from members.models.checkin import CheckIn
File "/Users/allenchun/Sites/augmify/simpli/members/models/checkin.py", line 6, in <module>
from merchants.models import MerchantLocation
File "/Users/allenchun/Sites/augmify/simpli/merchants/models/__init__.py", line 3, in <module>
from merchants.models.beacon import Beacon
File "/Users/allenchun/Sites/augmify/simpli/merchants/models/beacon.py", line 5, in <module>
from merchants.models.merchant_location import MerchantLocation
File "/Users/allenchun/Sites/augmify/simpli/merchants/models/merchant_location.py", line 4, in <module>
from django_countries import CountryField
ImportError: cannot import name CountryField
from django_countries.fields import CountryField
Example usage the the pypi documentation.
from django.db import models
from django_countries.fields import CountryField
class Person(models.Model):
name = models.CharField(max_length=100)
country = CountryField()
>>> person = Person(name='Chris', country='NZ')
>>> person.country
Country(code='NZ')
>>> person.country.name
'New Zealand'
>>> person.country.flag
'/static/flags/nz.gif'
I have this line in my appliaction's init.py:
from .signals import *
When I run gunicorn myproject.wsgi:application, it gives me this error:
Traceback (most recent call last):
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
worker.init_process()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
self.wsgi = self.app.wsgi()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
File "/webapps/venv/myproject/myproject/__init__.py", line 1, in <module>
from .signals import *
File "/webapps/venv/myproject/myproject/signals.py", line 1, in <module>
from django.db.models.signals import pre_delete
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Traceback (most recent call last):
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
worker.init_process()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
self.wsgi = self.app.wsgi()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/webapps/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
File "/webapps/venv/myproject/myproject/__init__.py", line 1, in <module>
from .signals import *
File "/webapps/venv/myproject/myproject/signals.py", line 1, in <module>
from django.db.models.signals import pre_delete
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/sql/aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "/webapps/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/webapps/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
If I disable the above-mentioned line in the __init__.py, gunicorn will start working.
Of course I can move the import line to another place and solve the issue, but I wonder why the error happens and if there's another way to resolve it.
By using the from .signals import * it seems you're getting an error due to the execution order.
Based on the error about DJANGO_SETTINGS_MODULE you need that defined in order to import from a model file. The issue I think is occurring is that the __init__.py file is getting executed when gunicorn goes to load your app, but before Django has actually loaded all of the application settings.
A potential fix may be to define the __all__ in your signals.py file.
Without more context to the issue though, it's tough to know.
Sentry
I've been using this to setup the environment: Sentry Setup
But when I get to this command:
sentry --config=/etc/sentry.conf.py upgrade
It gives me this error:
nope#not_telling_you-ubuntu:~/scratch$ sudo sentry --config=/etc/sentry.conf.py upgrade
Traceback (most recent call last):
File "/usr/local/bin/sentry", line 9, in <module>
load_entry_point('sentry==5.4.5', 'console_scripts', 'sentry')()
File "/usr/local/lib/python2.7/dist-packages/sentry-5.4.5-py2.7.egg/sentry/utils/runner.py", line 197, in main
initializer=initialize_app,
File "/usr/local/lib/python2.7/dist-packages/logan/runner.py", line 162, in run_app
management.execute_from_command_line([runner_name, command] + command_args)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 252, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 101, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 93, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/logan/importer.py", line 68, in load_module
return self._load_module(fullname)
File "/usr/local/lib/python2.7/dist-packages/logan/importer.py", line 92, in _load_module
load_settings(self.config_path, allow_extras=self.allow_extras, settings=settings_mod)
File "/usr/local/lib/python2.7/dist-packages/logan/settings.py", line 49, in load_settings
execfile(mod_or_filename, conf.__dict__)
File "/etc/sentry.conf.py", line 45, in <module>
dgin
django.core.exceptions.ImproperlyConfigured: NameError("name 'dgin' is not defined",)
asdas#asdas-ubuntu:~/scratch$
Any idea what could be going on? I've setup everything until this point.
"dgin" is an undefined variable in the sentry configuration
It's likely this is a mistype or something similar, but that's what the error means.
What I was trying to do was to override the save method of one of my models called Shastra
class Shastra(models.Model):
something = models.IntegerField()
def save(self, *args, **kwargs):
post_content(app='shastra', content=self)
super(Shastra, self).save(*args, **kwargs)
# The function being called in the override function
def post_content(*args, **kwargs):
FbApiContent(content = kwargs['content']).save()
# The model being used by the override function
from shastra.models import Shastra
class FbApiContent(models.Model):
content = models.ForeignKey(Shastra)
The Traceback
Traceback (most recent call last):
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220, in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
self.run(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 78, in run
self.inner_run(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\shastra\models.py", line 10, in <module>
from fb_api.api import *
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\api.py", line 7, in <module>
from fb_api.models import FbApiUser
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\models.py", line 41, in <module>
from shastra.models import Shastra
ImportError: cannot import name Shastra
I have no idea what's going on : |, any insights I would be grateful
Circular import. Either resolve it, or use string as FK argument (models.ForeignKey('app.Shastra')).
It looks like you have a circular import.
shastra\models.py is doing from fb_api.api import *
fb_api\api.py is doing from fb_api.models import FbApiUser
fb_api\models.py is doing from shastra.models import Shastra
Even if you just import one class from a module, the whole module gets executed to fill in it's namespace.