実現したいこと
- Djangoの管理画面('http://localhost:8000/admin/') にDebugToolbarが正しく表示されること
前提
- Djangoの公式ドキュメントのはじめてのDjangoアプリ作成、その8を見ながら作業中
- Django Debug Toolbarのパッケージインストールガイドを見ながら作業中
- パッケージのインストールは完了しています
- インストールガイドに沿って入力が完了したと思っています
発生している問題・エラーメッセージ
Internal Server Error: /admin/ Traceback (most recent call last): File "/Users/yukihito/.pyenv/versions/3.10.1/lib/python3.10/site-packages/django/urls/base.py", line 71, in reverse extra, resolver = resolver.namespace_dict[ns] KeyError: 'djdt'
該当のソースコード
python
1settings.py 2 3""" 4Django settings for mysite project. 5 6Generated by 'django-admin startproject' using Django 4.2.5. 7 8For more information on this file, see 9https://docs.djangoproject.com/en/4.2/topics/settings/ 10 11For the full list of settings and their values, see 12https://docs.djangoproject.com/en/4.2/ref/settings/ 13""" 14 15from pathlib import Path 16 17# Build paths inside the project like this: BASE_DIR / 'subdir'. 18BASE_DIR = Path(__file__).resolve().parent.parent 19 20 21# Quick-start development settings - unsuitable for production 22# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ 23 24# SECURITY WARNING: keep the secret key used in production secret! 25SECRET_KEY = 'django-insecure-*@kxu2@v0k9485lxl+%sn))+(mh(cuelb0ek-(hj5v8(0^kc!d' 26 27# SECURITY WARNING: don't run with debug turned on in production! 28DEBUG = True 29 30# Application definition 31 32INSTALLED_APPS = [ 33 "polls.apps.PollsConfig", 34 "django.contrib.admin", 35 "django.contrib.auth", 36 "django.contrib.contenttypes", 37 "django.contrib.sessions", 38 "django.contrib.messages", 39 "django.contrib.staticfiles", 40 "debug_toolbar", 41] 42 43STATIC_URL = "static/" 44 45MIDDLEWARE = [ 46 'django.middleware.security.SecurityMiddleware', 47 'django.contrib.sessions.middleware.SessionMiddleware', 48 'django.middleware.common.CommonMiddleware', 49 'django.middleware.csrf.CsrfViewMiddleware', 50 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 'django.contrib.messages.middleware.MessageMiddleware', 52 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 'debug_toolbar.middleware.DebugToolbarMiddleware', 54] 55 56 57ROOT_URLCONF = 'mysite.urls' 58 59TEMPLATES = [ 60 { 61 "BACKEND": "django.template.backends.django.DjangoTemplates", 62 "DIRS": [BASE_DIR / "templates"], 63 "APP_DIRS": True, 64 "OPTIONS": { 65 "context_processors": [ 66 "django.template.context_processors.debug", 67 "django.template.context_processors.request", 68 "django.contrib.auth.context_processors.auth", 69 "django.contrib.messages.context_processors.messages", 70 ], 71 }, 72 }, 73] 74 75INTERNAL_IPS = ["127.0.0.1"] 76 77WSGI_APPLICATION = 'mysite.wsgi.application' 78 79 80# Database 81# https://docs.djangoproject.com/en/4.2/ref/settings/#databases 82 83DATABASES = { 84 'default': { 85 'ENGINE': 'django.db.backends.sqlite3', 86 'NAME': BASE_DIR / 'db.sqlite3', 87 } 88} 89 90 91# Password validation 92# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators 93 94AUTH_PASSWORD_VALIDATORS = [ 95 { 96 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 97 }, 98 { 99 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 100 }, 101 { 102 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 103 }, 104 { 105 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 106 }, 107] 108 109 110# Internationalization 111# https://docs.djangoproject.com/en/4.2/topics/i18n/ 112 113LANGUAGE_CODE = 'en-us' 114 115TIME_ZONE = 'Asia/Tokyo' 116 117USE_I18N = True 118 119USE_TZ = True 120 121 122# Static files (CSS, JavaScript, Images) 123# https://docs.djangoproject.com/en/4.2/howto/static-files/ 124 125STATIC_URL = 'static/' 126 127# Default primary key field type 128# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field 129 130DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
python
1urls.py 2from django.urls import include, path 3 4 5from . import views 6 7 8app_name = "polls" 9urlpatterns = [ 10 path("", views.IndexView.as_view(), name="index"), 11 path("<int:pk>/", views.DetailView.as_view(), name="detail"), 12 path("<int:pk>/results/", views.ResultsView.as_view(), name="results"), 13 path("<int:question_id>/vote/", views.vote, name="vote"), 14 path("__debug__/", include("debug_toolbar.urls")), 15]
試したこと
- djdtという変数にうまく値が渡せていないことが原因と考えましたが、うまくコードの流れを理解できず難航しています。
- chatGPT3.5でエラーを質問してみたが、以下の返答がありコードを何度も見直したり、コピーして比較して書き直してみましたがエラーは解決しなかったです。
このエラーメッセージは、Django Debug Toolbar(djdt)を使用しようとしているときに、'djdt' is not a registered namespace('djdt'は登録された名前空間ではありません)というエラーが発生していることを示しています。このエラーは通常、設定に関連する問題がある場合に発生します。 以下のステップを確認して、問題を解決してみてください: settings.py ファイルの INSTALLED_APPS リストを確認してください。Django Debug Toolbarが正しくインストールされていることを確認し、以下のようになっているかどうかを確認してください: python Copy code INSTALLED_APPS = [ # ... 'debug_toolbar', # ... ] 'debug_toolbar' アプリケーションが正しくリストに含まれていることを確認してください。 settings.py ファイルに Debug Toolbar の設定を追加または確認してください。以下は設定の例です: python Copy code # Debug Toolbar の設定 if DEBUG: INTERNAL_IPS = [ # ... '127.0.0.1', # ローカルIPアドレス # ... ] MIDDLEWARE += [ 'debug_toolbar.middleware.DebugToolbarMiddleware', ] この設定は、DEBUG モードが有効な場合に Debug Toolbar を有効にします。INTERNAL_IPS には、Debug Toolbar を表示するために許可するIPアドレスが含まれていることを確認してください。 プロジェクトのルートURL設定ファイル(通常は urls.py)で、Debug Toolbar のURLパターンを正しく設定していることを確認してください。以下は設定の例です: python Copy code from django.urls import include, path urlpatterns = [ # ... path('__debug__/', include('debug_toolbar.urls')), # ... ] path('__debug__/', include('debug_toolbar.urls')) の部分が、Debug Toolbar のURL設定を追加しています。この行が正しく追加されていることを確認してください。 Djangoのサーバーを再起動して変更を適用してみてください。通常、設定の変更を反映させるにはサーバーの再起動が必要です。 これらのステップを確認して、問題が解決するかどうかを確認してみてください。問題が解決しない場合は、さらに詳細な情報が必要かもしれません。その場合は、追加のエラーメッセージや設定を提供していただければ、より具体的なサポートを提供できるかもしれません。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。