geekcomputers / geekcomputers/Python

heroku myapp.herokuapp.com/admin/ showing Server Error (500) and not serving images from s3 bucket

Open
#302 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
35.4k
Forks
12.9k
Avg merge
2h 37m
Merged PRs (30d)
1

Description

the url https://myapp.herokuapp.com working fine but the url https://myapp.herokuapp.com/admin/ showing Server Error (500) and it also not serving the images from the s3 bucket i already did these
`heroku run python manage.py migrate

heroku run python manage.py createsuperuser`

my settings.py file
"""
Django settings for ecommerce project.

Generated by 'django-admin startproject' using Django 1.11.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

from ecommerce.settings.aws.conf import *

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))))

EMAIL_HOST = 'smtp.gmail.com'

EMAIL_HOST_USER = 'abc@gmail.com'

EMAIL_HOST_PASSWORD = 'abc123'

EMAIL_PORT = 587

EMAIL_USE_TLS = True

DEFAULT_FROM_EMAIL = "rahul abc@gmail.com"

ADMINS = [('rahul', EMAIL_HOST_USER)]

MANAGERS = ADMINS

Quick-start development settings - unsuitable for production

See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = '$$!#%(2lqx#ckmc9#j6lw5ts4_9n$qjy$@=zv09wxvo_=qa=po'

SECURITY WARNING: don't run with debug turned on in production!

DEBUG = False

ALLOWED_HOSTS = ["shoppingwave.herokuapp.com"]

Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'products',
'storages',
'boto',

]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'ecommerce.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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 = 'ecommerce.wsgi.application'

Database

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

DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }

'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'online_shopping',
        'USER': 'postgres',
        'PASSWORD': 'abc2x',
        'HOST': '',
        'PORT': ''

    }

}

import dj_database_url
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

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'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Static files (CSS, JavaScript, Images)

https://docs.djangoproject.com/en/1.11/howto/static-files/

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "")
AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME", "")
AWS_QUERYSTRING_AUTH = False
AWS_S3_CUSTOM_DOMAIN = os.environ.get("AWS_S3_CUSTOM_DOMAIN", "")
MEDIA_ROOT = os.environ.get("MEDIA_URL", "")
MEDIA_URL = '/media/'

MEDIA_URL = '/media/'

STATIC_URL = '/static/'

STATICFILES_DIRS = (

os.path.join(BASE_DIR, 'static-storage'),

)

STATIC_ROOT = os.path.join(BASE_DIR, 'live-static-files', "static-root")

MEDIA_ROOT = os.path.join(BASE_DIR, 'live-static-files', "media-root")

# STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static-serve', 'static_root')

# MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static-serve', 'media_root')

STATICFILES_FINDERS = (

'django.contrib.staticfiles.finders.FileSystemFinder',

'django.contrib.staticfiles.finders.AppDirectoriesFinder',

)

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_STORAGE_BUCKET_NAME = 'darkmachine'

AWS_ACCESS_KEY_ID = 'A55'

AWS_SECRET_ACCESS_KEY = '64E2hWFqCk'

S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME

MEDIA_URL = S3_URL + '/media/'

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

STATIC_URL = S3_URL + '/static/'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by checking the Heroku error output for the /admin/ request, then review the provided settings.py configuration for the database and S3 media settings. Done means the traceback identifies a resolved cause, the admin page loads without a 500 error, and the deployed application serves its S3 images.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, django, postgresql, python
Domain
backend, cloud, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.