Open Abishek05 opened 5 years ago
Dude you have posted a lot of critical configs related to your environment. Replace them ASAP before anyone misuses them. Be careful in future !
@superappy For obvious reasons i have changed the credentials before posting. Thanks for your concern. Any insights on the issue?
Context
Hello, I'm using django cms. Media files are not displayed after i deploy the application. when i try to upload an image using carousel slides, the request times out. Image uploads are not successful.
I'm facing this issue only in production environment. I've setup the static path and media path pointing to aws s3 bucket using django storages .
Although static files are being loaded from s3.
Database used- AWS RDS mysql instance
Expected Behavior
Media files such as images should be loaded from s3.
Actual Behavior
Media files are not being loaded in production. Upload images are unsuccessful.
Possible Fix
I'm not sure, but something in zappa is not substituting the media files url properly after the project is zipped.
Steps to Reproduce
Generated by 'django-admin startproject' using Django 1.11.15.
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
Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
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!
SECRETKEY = '2d-yyc@k&d%5&o2p8hje#duncrtmx8)2vig69$k@5_bubigygfc'
SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
Application definition
ROOT_URLCONF = 'mysite.urls'
Internationalization
https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en'
TIME_ZONE = 'Asia/Calcutta'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'static')
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'mysite', 'static'), ) SITE_ID = 1
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'mysite', 'templates'),], 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.i18n', 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.template.context_processors.media', 'django.template.context_processors.csrf', 'django.template.context_processors.tz', 'sekizai.context_processors.sekizai', 'django.template.context_processors.static', 'cms.context_processors.cms_settings' ], 'loaders': [ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 'django.template.loaders.eggs.Loader' ], }, }, ]
MIDDLEWARE = ( 'cms.middleware.utils.ApphookReloadMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware' )
INSTALLED_APPS = ( 'djangocms_admin_style', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.sitemaps', 'django.contrib.staticfiles', 'django.contrib.messages', 'cms', 'menus', 'sekizai', 'treebeard', 'djangocms_text_ckeditor', 'filer', 'easy_thumbnails', 'djangocms_column', 'djangocms_file', 'djangocms_link', 'djangocms_picture',
'djangocms_style',
)
LANGUAGES = (
Customize this
)
CMS_LANGUAGES = {
Customize this
}
CMS_TEMPLATES = (
Customize this
)
CMS_PERMISSION = True
CMS_PLACEHOLDER_CONF = {} ''' DATABASES = { 'default': { 'CONN_MAX_AGE': 0, 'ENGINE': 'django.db.backends.sqlite3', 'HOST': 'localhost', 'NAME': 'project.db', 'PASSWORD': '', 'PORT': '', 'USER': '' } } ''' ''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'rdzcivlp', 'USER': 'rdzcivlp', 'PASSWORD': 'DVv-uJ8d0FL7SO1sTCBaBXGgbuug0b', 'HOST': 'baasu.db.elephantsql.com', 'PORT': '5432' } } ''' ''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'cmscoldchip', 'USER': 'blackweb', 'PASSWORD': '$hnpiiy8gbb97ttgbi80', 'HOST': 'webinstance.cyrb6swhdrez.us-west-2.rds.amazonaws.com', 'PORT': '5432' } } ''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'cmscoldchip', 'USER': 'blackweb', 'PASSWORD': 'jn[mm[0i9hgbiiyif75ed7utfj', 'HOST': 'webinstance-mysql.cyrb6swhdrez.us-west-2.rds.amazonaws.com', 'PORT': '3306' } }
MIGRATION_MODULES = {
}
THUMBNAIL_PROCESSORS = ( 'easy_thumbnails.processors.colorspace', 'easy_thumbnails.processors.autocrop', 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 'easy_thumbnails.processors.filters' )
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = 'zappa-djangostaticcms' AWS_ACCESS_KEY_ID = 'AKIAJ35I3SP3SUJBHJGJH' AWS_SECRET_ACCESS_KEY = 'R1RM6GwYSB1tRFNXT0RgFv4IIhih80y9080' AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
STATICFILES_LOCATION = 'static' STATICFILES_STORAGE = 'custom_storages.StaticStorage' STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
MEDIAFILES_LOCATION = 'media' MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION) DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
AWS_S3_REGION_NAME = 'us-west-2' MEDIA_ROOT = MEDIA_URL
AWS_DEFAULT_ACL = None AWS_QUERYSTRING_AUTH = False
custom_storages.py
from django.conf import settings from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage): location = settings.STATICFILES_LOCATION
class MediaStorage(S3Boto3Storage): location = settings.MEDIAFILES_LOCATION
-- coding: utf-8 --
from future import absolute_import, print_function, unicode_literals
from cms.sitemaps import CMSSitemap from django.conf import settings from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.contrib.sitemaps.views import sitemap from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.static import serve
admin.autodiscover()
urlpatterns = [ url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}), ]
urlpatterns += i18n_patterns( url(r'^admin/', include(admin.site.urls)), # NOQA url(r'^', include('cms.urls')), )
This is only needed when using runserver.
if settings.DEBUG: urlpatterns = [ url(r'^media/(?P.*)$', serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
] + staticfiles_urlpatterns() + urlpatterns