ちょうどdjangoチュートリアルを完了しました。設定フォルダを作成し、base.pyでデータベースを再設定した後、私のウェブサイトはロードされていませんImportError。何かご意見は?ここでImportError:モジュールがありませんdiversely.settings.dev
は、トレースバックです:ここでは
Traceback (most recent call last):
File "/Users/m.zayas/Desktop/env1/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/m.zayas/Desktop/env1/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/m.zayas/Desktop/env1/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "/Users/m.zayas/Desktop/env1/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/Users/m.zayas/Desktop/env1/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/m.zayas/Desktop/env1/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named diversely.settings.dev
は私base.pyです:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_h0tyj2^#5x2jh$9!&p0589-zop-0aiwok)x(sf+u-jjhw9l*o'
# SECURITY WARNING: don't run with debug turned on in production!
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',
'accounts',
'home',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
'diversely.middleware.LoginRequiredMiddleware'
]
ROOT_URLCONF = 'diversely.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'accounts/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'diversely.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/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.10/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'diversely/media')
LOGIN_REDIRECT_URL = '/home/'
LOGIN_URL = '/account/login'
LOGIN_EXEMPT_URLS = (
r'^account/logout/$',
r'^account/register/$',
r'^account/reset-password/$',
r'^account/reset-password/done/$',
r'^account/reset-password/$',
r'^account/reset-password/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
r'^account/reset-password/complete/$',
)
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
私のWSGI:
"""
WSGI config for diversely project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "diversely.settings.prod")
application = get_wsgi_application()
dev.py:
from diversely.settings.base import *
# Override base.py settings here
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
try:
from diversely.settings.local import *
except:
pass
は
prod.py:
from diversely.settings.base import *
# Override base.py settings here
DEBUG = False
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
try:
from diversely.settings.local import *
except:
pass
フォルダ構造: ここに私のフォルダ構造です:あなたのフォルダ構造は次のようにする必要があります
diversely
Ldiversely
L settings.py
L __init__.py
L base.py
L dev.py
L local.py
L production.py
settings.pyの名前をbase.pyに変更しましたか?あなたはフォルダ構造を投稿することができます – Exprator
明らかに、それは 'PYTHONPATH'問題です。 'diversely.settings'パッケージを含むフォルダを' PYTHONPATH'に追加する必要があります。 –
manage.pyファイルを確認してください –