Django 1.6をOSX10.8にpython 2.7でインストールしましたが、チュートリアルの実行に問題があります。次のコマンドを実行してmysiteというサーバーの作成を設定した後:
Django-admin.py startproject mysite
次に、mysiteにcdして実行しました
python manage.py runserver
そしてこのエラーが発生しました:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/Django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Library/Python/2.7/site-packages/Django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Library/Python/2.7/site-packages/Django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Library/Python/2.7/site-packages/Django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Python/2.7/site-packages/Django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Library/Python/2.7/site-packages/Django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/Django/contrib/admin/__init__.py", line 6, in <module>
from Django.contrib.admin.sites import AdminSite, site
File "/Library/Python/2.7/site-packages/Django/contrib/admin/sites.py", line 4, in <module>
from Django.contrib.admin.forms import AdminAuthenticationForm
File "/Library/Python/2.7/site-packages/Django/contrib/admin/forms.py", line 6, in <module>
from Django.contrib.auth.forms import AuthenticationForm
File "/Library/Python/2.7/site-packages/Django/contrib/auth/forms.py", line 17, in <module>
from Django.contrib.auth.models import User
File "/Library/Python/2.7/site-packages/Django/contrib/auth/models.py", line 361, in <module>
class AbstractUser(AbstractBaseUser, PermissionsMixin):
File "/Library/Python/2.7/site-packages/Django/db/models/base.py", line 212, in __new__
new_class.add_to_class(field.name, copy.deepcopy(field))
File "/Library/Python/2.7/site-packages/Django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Python/2.7/site-packages/Django/db/models/fields/__init__.py", line 303, in contribute_to_class
cls._meta.add_field(self)
File "/Library/Python/2.7/site-packages/Django/db/models/options.py", line 172, in add_field
self.local_fields.insert(bisect(self.local_fields, field), field)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
.........
このエラーは、最後まで繰り返し印刷されることになります。
ファイル "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py"、56行目、 '_lt_ ':[(' _gt_ '、lambda self、other:other <self)、
そして、出力の最後の数行は次のとおりです。
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda>
'__lt__': [('__gt__', lambda self, other: other < self),
RuntimeError: maximum recursion depth exceeded while calling a Python object
最後の行を見た後:
RuntimeError: maximum recursion depth exceeded while calling a Python object
私も走った:
Django-admin.py check
そしてこの出力を得ました:
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.
また、次のように入力して、tcshで環境変数を設定してみました。
setenv Django_SETTINGS_MODULE "mysite.settings"
しかし、それでも再帰深度エラーが発生しました。ランニング
Django-admin.py check
それから私にこのエラーを与えました:
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named mysite.settings
これが私のsettings.pyです:
"""
Django settings for mysite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3e%g^*y!3$2=ln75%usf2ftjf&urt7&kuj@_-yc+53pjm)$@9^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'Django.contrib.admin',
'Django.contrib.auth',
'Django.contrib.contenttypes',
'Django.contrib.sessions',
'Django.contrib.messages',
'Django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'Django.contrib.sessions.middleware.SessionMiddleware',
'Django.middleware.common.CommonMiddleware',
'Django.middleware.csrf.CsrfViewMiddleware',
'Django.contrib.auth.middleware.AuthenticationMiddleware',
'Django.contrib.messages.middleware.MessageMiddleware',
'Django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'Django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
そして私のファイル構造:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
__init__.pyc
settings.pyc
wsgi.py
私はDjangoの初心者で、本当に行き詰まっています。誰かが洞察を提供できますか?
さて、ようやく答えが見つかりました。どうやらエラーはPython2.7.2。2.7.6にアップグレードすると、問題は解決しました。
これが私が答えを見つけた同様のスレッドです:
実行中にcmpエラーで最大再帰深度を超えましたpython manage.py runserver
このスレッドを作成しているときに、なぜこのソリューションが検索に表示されなかったのかわかりません...
チェックイン manage.py
これがある場合:
import os
if __name__ == "__main__":
os.environ.setdefault("Django_SETTINGS_MODULE", "mysite.settings")
そしてwsgi.py
この:
import os
os.environ.setdefault("Django_SETTINGS_MODULE", "mysite.settings")
また、pythonを統合するDjangoスクリプトは、次のようになります。
import os
os.environ.setdefault("Django_SETTINGS_MODULE", "mysite.settings")
# Uncomment below for Django 1.7 +
#import Django
#Django.setup()