9

I am trying to deploy a Django app on EC2 Instance. I had put my EC2 instance in the Allowed_Host correctly. but it kept giving me a Disallowed_Host error. I have been trying to fix that but Now I get the.

Django TemplateDoesNotExist at / debug_toolbar/base.html Error

Can anyone advise on what I am doing wrong? Below are my screenshots and code. By the way it works perfectly fine in my development 127.0.0.1

enter image description here

Also below is the Traceback just in case

enter image description here

I have attached my settings.py file below

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "1111111111111111111111"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["ec2-11-111-111-11.compute-1.amazonaws.com", "127.0.0.1", "Siteevent.com", "www.Siteevent.com"]


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'bootstrap3',
    'accounts',
    'groups',
    'posts',
    'proof',
    'feeds',
    'questions',
    'tasting',
    'verification',
    'cart',
    'stripe',
    'order',
    'report',
    'django_cleanup',
    'bootstrap_datepicker_plus',
    'social_django',
    'storages',
    'captcha',


]

AUTHENTICATION_BACKENDS = [

    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
    'accounts.authentication.EmailAuthBackend',

]


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',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]

ROOT_URLCONF = 'Site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR, os.path.join(BASE_DIR, 'order', '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',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
                'cart.context_processors.counter',
            ],
        },
    },
]

WSGI_APPLICATION = 'Site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'Site_event',
        'USER': '11111111111111111111111',
        'PASSWORD': '11111111111111111111111111',
        'HOST': 'Site-event1111111111111111111111111rds.amazonaws.com',
        'PORT': '5432',
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/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.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

# TIME_ZONE = 'UTC'
TIME_ZONE = "America/New_York"
USE_TZ = True

USE_I18N = True

USE_L10N = True

AWS_DEFAULT_ACL = None
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
DEFAULT_FILE_STORAGE = 'aws_storage_classes.MediaStorage'
AWS_STORAGE_BUCKET_NAME = 'Site-media-1111111111111'
STATICFILES_STORAGE = 'aws_storage_classes.StaticStorage'
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}

AWS_S3_DOMAIN = "%s.s3.amazonaws.com" % AWS_STORAGE_BUCKET_NAME


STATIC_URL = 'https://%s/static/' % AWS_S3_DOMAIN
MEDIA_URL = 'https://%s/media/' % AWS_S3_DOMAIN

ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'


LOGIN_REDIRECT_URL = 'loggedin'
LOGOUT_REDIRECT_URL = 'accounts:login'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '1111111111111111111111111111111111111111111'
SOCIAL_AUTH_GOOGLE_OAUTH_SECRET = '111111111111111111111111111111111111111111'


INTERNAL_IPS = ('127.0.0.1', )

BOOTSTRAP3 = {
    'include_jquery': True,
}

DATE_INPUT_FORMATS = ['%b %d %Y']

TIME_INPUT_FORMATS = ['%I:%M %p']

####Stripe Settings###

STRIPE_PUBLISHABLE_KEY = '11111111111111111111111111111111111'
STRIPE_SECRET_KEY = '11111111111111111111111111111111111'


RECAPTCHA_PUBLIC_KEY = "11111111111111111111111111111111111111111111"
RECAPTCHA_PRIVATE_KEY = "111111111111111111111111111111"


# try:
#     from Site.local_settings import *
# except ImportError as e:
#     pass
#

Adding django_toolbar to the INSTALED_APPS gives the error below

enter image description here

I even tried removing the django_tooldbar and the middleare involved that gave me a same error just at a different place

enter image description here

Samir Tendulkar
  • 1,151
  • 3
  • 19
  • 47

3 Answers3

24

The error is occurring because you have included debug_toolbar in middleware but not in the INSTALLED_APPS. So either you need to remove 'debug_toolbar.middleware.DebugToolbarMiddleware', from MIDDLEWARE.

OR add debug_toolbar to INSTALLED_APPS. Reference to django_toolbar.

ruddra
  • 50,746
  • 7
  • 78
  • 101
  • I tried both your suggestions I get a `No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials` error see image above – Samir Tendulkar Feb 19 '19 at 12:24
  • @MarcoBianchi I think you can look into this: https://stackoverflow.com/questions/41201422/aws-boto-no-handler-after-configuration – ruddra Feb 19 '19 at 16:32
  • thanks your solution resolved my debug_toolbar issue – Samir Tendulkar Feb 20 '19 at 01:51
2

I had the same problem.

But for me that was caused by INTERNAL_IPS.

When it is set to : INTERNAL_IPS = ['127.0.0.1', ] and trying access http://localhost:8000/ that doesn't work, neither with ip adress.

But if it is turned to : INTERNAL_IPS = ['localhost', ] that works fine with both http://127.0.0.1:8000/ and http://localhost:8000/.

gxmad
  • 1,650
  • 4
  • 23
  • 29
0

After removing the Django Debud Tool Bar from installed apps, you have to remove it from MiddleWares section too.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 16 '23 at 05:18