I was trying to use django-debug-toolbar but it doesnt show up at all, so i tried inspecting my page and i found out theres actually a erro 403 forbidden that is hiding the toolbar. I've tried everything i knew and searched on the internet like a maniac but what solved someone elses problem wasnt working for me. Sorry if the code is hard to understand, i'm still a novice programmer. If any other information is required pelase let me know
settings.py:
import mimetypes
from functools import partial
import dj_database_url
from primeiraAplicacaoDjango import base # noqa
from pathlib import Path
from decouple import config, Csv
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
AUTH_USER_MODEL = 'base.User'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'collectfast',
'django.contrib.staticfiles',
'primeiraAplicacaoDjango.base',
]
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 = 'primeiraAplicacaoDjango.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 = 'primeiraAplicacaoDjango.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
default_db_url = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
parse_database = partial(dj_database_url.parse, conn_max_age=600)
DATABASES = {
'default': config('DATABASE_URL', default=default_db_url, cast=parse_database)
}
# Password validation
# https://docs.djangoproject.com/en/4.0/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',
},
]
# Config da Django-debug-toolbar
INTERNAL_IPS = config('INTERNAL_IPS', cast=Csv(), default='127.0.0.1')
if DEBUG:
INSTALLED_APPS.append('debug_toolbar')
MIDDLEWARE.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware')
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'pt-br'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
# Configuração de ambiente de desenvolvimento
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
COLLECTFAST_ENABLED = False
def show_toolbar(request):
return True
SHOW_TOOLBAR_CALLBACK = show_toolbar
mimetypes.add_type("application/javascript", ".js", True)
DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
}
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
COLLECTFAST_STRATEGY = 'collectfast.strategies.boto3.Boto3Strategy'
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
# STORAGE CONFIGURATION FOR S3 AWS
# ---------------------------------
if AWS_ACCESS_KEY_ID:
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400', }
AWS_PRELOAD_METADATA = True
AWS_AUTO_CREATE_BUCKET = False
AWS_QUERYSTRING_AUTH = True
AWS_S3_CUSTOM_DOMAIN = None
AWS_DEFAULT_ACL = 'private'
COLLECTFAST_ENABLED = True
# static assets
STATICFILES_STORAGE = 's3_folder_storage.s3.StaticStorage'
STATIC_S3_PATH = 'static'
STATIC_ROOT = f'/{STATIC_S3_PATH}/'
STATIC_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{STATIC_S3_PATH}/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
# Upload Media Folder
DEFAULT_FILE_STORAGE = 's3_folder_storage.s3.DefaultStorage'
DEFAULT_S3_PATH = 'media'
MEDIA_ROOT = f'/{DEFAULT_S3_PATH}/'
MEDIA_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{{DEFAULT_S3_PATH}}/'
INSTALLED_APPS.append('s3_folder_storage')
INSTALLED_APPS.append('storages')
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
views.py:
from django.shortcuts import render # noqa
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def home(request):
return HttpResponse('<html><body>Olá Django!</body></html>', content_type='text/html')
urls.py:
from django.urls import include
from django.conf import settings
from primeiraAplicacaoDjango.base.views import home
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns.append(
path('__debug__/', include(debug_toolbar.urls))
)
I found the answer last month, forgot to post here, it was actually a weird error on my settings.py that somehow was solved by copying and pasting the same code again