前提・実現したいこと
前提:
Djangogirlsチュートリアルの「Djangoビュー(https://tutorial.djangogirls.org/ja/django_views/)」が上手くいきません。その手前の「Django URLs」までは何も問題なく進められていました。
実現したいこと:
チュートリアル通り、ローカル環境で、TemplateDoesNotExistのエラーを表示させたい。
発生している問題・エラーメッセージ
以下は、関連のありそうなところのそれぞれの内容とエラーメッセージです。
### 1⃣djangogirls/blog/urls.py
from django.urls import path from . import views urlpatterns = [ path('', views.post_list, name='post_list'), ]
Traceback (most recent call last): File "/home/ec2-user/environment/djangogirls/blog/urls.py", line 2, in <module> from . import views ImportError: cannot import name 'views' Process exited with code: 0
### 2⃣djangogirls/mysite/urls.py
from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('blog.urls')), ]
Traceback (most recent call last): File "/home/ec2-user/environment/djangogirls/mysite/urls.py", line 20, in <module> path('admin/', admin.site.urls), File "/usr/local/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 285, in urls return self.get_urls(), 'admin', self.name File "/usr/local/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 237, in get_urls from django.contrib.contenttypes import views as contenttype_views File "/usr/local/lib/python3.6/site-packages/django/contrib/contenttypes/views.py", line 2, in <module> from django.contrib.contenttypes.models import ContentType File "/usr/local/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 134, in <module> class ContentType(models.Model): File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__ app_config = apps.get_containing_app_config(module) File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config self.check_apps_ready() File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. Process exited with code: 0
### 3⃣djangogirls/blog/views.py
from django.shortcuts import render def post_list(request): return render(request, 'blog/post_list.html', {})
Process exited with code: 0
### 4⃣djangogirls/mysite/wsgi.py
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') application = get_wsgi_application()
Traceback (most recent call last): File "/home/ec2-user/environment/djangogirls/mysite/wsgi.py", line 7, in <module> application = get_wsgi_application() File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup self._wrapped = Settings(settings_module) File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib64/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 941, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'mysite' Process exited with code: 0
### 5⃣djangogirls/mysite/settings
import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'wtl#%!7ccqt)t53uh3ri6cn@1&v-&*+g20)5r3!kbp+o_0nm3h' DEBUG = True ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com', '.amazonaws.com'] INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog.apps.BlogConfig', ] 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', ] ROOT_URLCONF = 'mysite.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], '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 = 'mysite.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } 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', }, ] LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Process exited with code: 0
### 補足:ちなみに、ローカル環境でのサーバーは、以下のように正常に動いているようです。
System check identified no issues (0 silenced). October 29, 2019 - 18:09:55 Django version 2.0.2, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
(myvenv) alcohole:~/environment/djangogirls (master) $ python manage.py check System check identified no issues (0 silenced).
追記(10/29/19:38):manage.pyそのものをrunさせてみたところ、最後に「Pane is Dead」というエラーメッセージが出ていました。もしかしたらこれが根本的な原因かもしれませんが、調べても対処法がピンときません...以下はその詳細です。
Type 'manage.py help <subcommand>' for help on a specific subcommand. Available subcommands: [auth] changepassword createsuperuser [contenttypes] remove_stale_contenttypes [django] check compilemessages createcachetable dbshell diffsettings dumpdata flush inspectdb loaddata makemessages makemigrations migrate sendtestemail shell showmigrations sqlflush sqlmigrate sqlsequencereset squashmigrations startapp startproject test [sessions] clearsessions [staticfiles] collectstatic findstatic runserver Process exited with code: 0 Pane is dead
試したこと
検索したところ、どこのサイトでも同様のエラーが出るのは大抵
①settings内のSECRET KEYの設定漏れ
②settings内のINSTALLED APPへの追記漏れ
③wsgi.pyの記入漏れ
のどれかと出てきましたが、どれも出来ているように見えるので、途方に暮れています。
補足情報(FW/ツールのバージョンなど)
server EC2
platform Amazon Linux
IDE AWS Cloud9
Python 3.6.8
pip 19.3.1(python3.6)
Django 2.0.2
何卒、よろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/10/29 10:04
2019/10/29 10:20 編集
退会済みユーザー
2019/10/29 10:25 編集
2019/10/29 10:27
退会済みユーザー
2019/10/29 10:35
2019/10/29 10:43
退会済みユーザー
2019/10/29 11:03 編集
2019/10/29 11:09 編集
退会済みユーザー
2019/10/29 12:37
2019/10/29 12:51 編集