Django server can not run, why? - django

E:\pythonwebproject\pythonweb>python manage.py runserver
Validating models...
Unhandled exception in thread started by <function wrapper at 0x01DE69F0>
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\django\utils\autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_r
self.validate(display_num_errors=True)
File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 277, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 35, in get_validation_
for (app_name, error) in get_app_errors().items():
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors
self._populate()
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 72, in _populate
self.load_app(app_name, True)
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 96, 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:\Python26\Lib\site-packages\django\contrib\auth\models.py", line 21, in <module>
from django.contrib.contenttypes.models import ContentType
File "C:\Python26\Lib\site-packages\django\contrib\contenttypes\models.py", line 127, in <module>
class ContentType(models.Model):
File "C:\Python26\Lib\site-packages\django\db\models\base.py", line 88, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
TypeError: Error when calling the metaclass bases
__init__() keywords must be strings

This bug report is the only resource I can find with similar symptoms. Are you using django 1.5? Try upgrading your python install to 2.7 and see if that rectifies the issue.

You are using the development version of Django (soon to be 1.5) with Python 2.6. It only works with 2.7 and 3.3. You should either upgrade your Python version, or use the released Django version 1.4.

Related

ImportError: No module named social_django.middleware

Hello I'm new to python and Django. Currently I'm trying to run a project made in django 1.10.2 and python 2.7 in ubuntu 16.04. The project uses a module called python-social-auth and when I try to run the project I get the following error:
python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7fb7d118a758>
Traceback (most recent call last):
File "/home/mauricio/.local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/mauricio/.local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 39, in inner_run
http_consumer=self.get_consumer(*args, **options),
File "/home/mauricio/.local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 134, in get_consumer
return StaticFilesConsumer()
File "/home/mauricio/.local/lib/python2.7/site-packages/channels/handler.py", line 327, in _init_
self.handler = self.handler_class()
File "/home/mauricio/.local/lib/python2.7/site-packages/channels/staticfiles.py", line 18, in _init_
super(StaticFilesHandler, self).__init__()
File "/home/mauricio/.local/lib/python2.7/site-packages/channels/handler.py", line 177, in _init_
self.load_middleware()
File "/home/mauricio/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 80, in load_middleware
middleware = import_string(middleware_path)
File "/home/mauricio/.local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named social_django.middleware
being that I already have the python-social-auth module installed.
Hopefully you can help me in detail to solve this problem because as I told you I am new to using these tools.

pkg_resources.DistributionNotFound: Django==1.8.3 in Django 1.9

I use Django 1.9 after updating of Django 1.8, and when i type command
django-admin runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Django==1.8.3
And then I try to type this one command:
django-admin.py runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, 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 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, 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 "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.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.
I try uninstall and install Django. But i still have this errors. Hope somebody can help me with it. Thanks
You shouldn't normally use django-admin, except when you do django-admin startproject.
After you have created the project, it is easier to use manage.py to run the dev server, because it takes care of setting the path and settings module for you.
./manage.py runserver
See the docs for more information.
Maybe you used another python version? It is python 2.7 now, and it seems you don't installed django properly for python2.7. You can try
python3 manage.py runserver
for using python3 in ubuntu (it is installed by default and accessibler with python3), or try to define how to run it with another python version.

migrate failure (django 1.8)

I'm trying in vain to migrate my database to the server. here is the traceback that I get from the terminal.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv) File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute() File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/core/management/__init__.py", line 328, in execute
django.setup() File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS) File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models) File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name) File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name) File "/home/guimatsi/lib/python2.7/registration/models.py", line 15, in <module>
User = get_user_model() File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/contrib/auth/__init__.py", line 150, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL) File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/apps/registry.py", line 199, in get_model
self.check_models_ready() File "/home/guimatsi/webapps/nnmland/lib/python2.7/Django-1.8.6-py2.7.egg/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Since I'm new in django and it's my first project, Every hint would be appreciated. ths in advance.
It looks like you might be using a version of Django registration that does not support Django 1.8. You could try installing Django registration redux instead.

django 1.3 server error

I am using django version 1.3. Python manage.py runserver 0.0.0.0:8000 gives the following error.
Validating models...
Unhandled exception in thread started by < bound method Command.inner_run of < django.contrib.staticfiles.management.commands.runserver.Command object at 0x20eb110>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_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/tastypie/models.py", line 6, in <module>
from tastypie.utils import now
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/__init__.py", line 1, in <module>
from tastypie.utils.dict import dict_strip_unicode_keys
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/dict.py", line 1, in <module>
from django.utils.encoding import smart_bytes
ImportError: cannot import name smart_bytes
Its working fine with django 1.4.2+, I was using django1.4 then upgraded it
pip install django==1.4.5 --upgrade
Django 1.3 had the issues of smart_bytes, and from your traceback it shows the same error, its been resolved in Django 1.4, Try upgrading Django to the latest version of 1.5.
See https://github.com/django/django/blob/master/django/utils/encoding.py#L149
Also, always check the release notes before upgrading your Django.
Update:
Sorry about that, wow, what a brainfart ;).
I don't know the full history of that function, but looking at django.utils.encoding on Github.. tagged 1.3.7; this file does not contain the function that Tastypie is attempting to import. https://github.com/django/django/blob/1.3.7/django/utils/encoding.py
If you cannot upgrade Django, you'll need to patch your Tastypie.utils.dict file to work with what you have.

Python 2.7 Django/MySQL issue

I was using Django with Python 2.7 on Windows 7 and I installed XAMPP and used the PHPMyAdmin MySQL included with it to create a database to use in Django, but when I went and used the "python manage.py syncdb" command, I got this error:
Traceback (most recent call last):
File "iFriends\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from
_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_comman
d
klass = load_command_class(app_name, subcommand)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 69, in load_command_
class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 8, in <module
>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have checked the host, username, password and those are correct, I really want to use Django so if anyone can help me on this, that would be great.
You need to install mysql lib for windows.
http://www.codegood.com/archives/4
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
http://www.codegood.com/archives/129
You require a dependency
easy_install mysql-python