EJEMPLO PROYECTO BLOG

base.py

# from django.core.exceptions import ImproperlyConfigured
# import json


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from unipath import Path
BASE_DIR = Path(__file__).ancestor(3)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# with open("secret.json") as f:
#     secret = json.loads(f.read())

# def get_secret(secret_name, secrets=secret):
#     try:
#         return secrets[secret_name]
#     except:
#         msg = "la variable %s no existe" % secret_name
#         raise ImproperlyConfigured(msg)


SECRET_KEY = '^cv997**%ht!&!+qunlefo#2i&7#tfn-9#1d5_253hhi8516#f'


# Application definition

DJANGO_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.postgres',
)

LOCAL_APPS = (
    'applications.users',
    'applications.home',
    'applications.entrada',
    'applications.favoritos',
)

THIRD_PARTY_APPS = (
    'ckeditor',
    'ckeditor_uploader',
    # 'import_export',
    #'django_quill',
)


INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS + THIRD_PARTY_APPS

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 = 'blog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR.child('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',
                'applications.procesors.home_contact',
            ],
        },
    },
]

WSGI_APPLICATION = 'blog.wsgi.application'


# Password validation
# https://docs.djangoproject.com/en/2.2/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',
    },
]

AUTH_USER_MODEL = 'users.User'

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Lima'
# TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

local.py

from .base import *
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blogdb',
        'USER': 'neunapp',
        'PASSWORD': 'neunapp2020',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR.child('static')]

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR.child('media')

# CKEDITOR SETTINGS
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = 'pillow'
CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'

CKEDITOR_CONFIGS = {
    'default': {
        'width': 'full',
        'height':'350',

        'toolbar': 'Custom',
        'toolbar_Custom' : [
            ['Bold', 'Italic', 'Underline'],
            ['NumberedList', 'BulletedList', '-', 'OutIdent', 'Ident', '-', 'JustifyLeft', 'JustifyRight', 'JustifyCenter'],
            ['TextColor', 'Format', 'FontSize', 'Link'],
            #['Smiley', 'Image', 'Iframe'],
            ['Image', 'Smiley', 'Iframe'],
            ['RemoveFormat', 'Source'],
        ],
        'stylesSet':[
        ],
    },
        'special':{
        'toolbar':'Special',
 #You can change this based on your requirements.
        'width': '100%',
        'height':'350',
        'toolbar_Special':[
        # ['Bold','CodeSnippet'],
        ['Bold', 'Italic', 'Underline'],
            ['NumberedList', 'BulletedList', '-', 'OutIdent', 'Ident', '-', 'JustifyLeft', 'JustifyRight', 'JustifyCenter'],
            ['TextColor', 'Format', 'FontSize', 'Link'],
            #['Smiley', 'Image', 'Iframe'],
            ['Image', 'Smiley', 'Iframe'],
            ['RemoveFormat', 'Source'],
              ['CodeSnippet'],
              ['CodeSnippet'],
        ],
        'extraPlugins':'codesnippet',
    }
}

#configuracion basica de ckeditor
# CKEDITOR_CONFIGS = {
#     'default': {
#         'toolbar': 'full',
#     },
# }


#configuracion de QUILL

# QUILL_CONFIGS = {
#     'default':{
#         'theme': 'snow',
#         'modules': {
#             'syntax': True,
#             'toolbar': [
#                 ['bold', 'italic', 'underline', 'strike'], 
#                 ['blockquote', 'code-block', 'link'],

#                 [{ 'header': 1 }, { 'header': 2 }, { 'header': 3 }],
#                 [{ 'list': 'ordered'}, { 'list': 'bullet' }],
#                 [{ 'script': 'sub'}, { 'script': 'super' }],
#                 [{ 'indent': '-1'}, { 'indent': '+1' }],
#                 [{ 'direction': 'rtl' }],

#                 [{ 'size': ['small', True, 'large', 'huge'] }],
#                 [{ 'header': [1, 2, 3, 4, 5, 6, False] }],

#                 [{ 'color': [] }, { 'background': [] }],
#                 [{ 'font': [] }],
#                 [{ 'align': [] }],

#                 ['clean']
#             ]
#         }
#     }
# }


# EMAIL SETTINGS
# EMAIL_USE_TLS = True
# EMAIL_HOST = 'smtp.gmail.com'
# EMAIL_HOST_USER = get_secret('EMAIL')
# EMAIL_HOST_PASSWORD = get_secret('PASS_EMAIL')
# EMAIL_PORT = 587

 

prod.py

from .base import *
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blogdb',
        'USER': 'neunapp',
        'PASSWORD': 'neunapp2020',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR.child('static')]
STATIC_ROOT = BASE_DIR.child('staticfiles')

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR.child('media')

# CKEDITOR SETTINGS
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = 'pillow'
CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'

CKEDITOR_CONFIGS = {
    'default': {
        'width': 'full',
        'height':'350',

        'toolbar': 'Custom',
        'toolbar_Custom' : [
            ['Bold', 'Italic', 'Underline'],
            ['NumberedList', 'BulletedList', '-', 'OutIdent', 'Ident', '-', 'JustifyLeft', 'JustifyRight', 'JustifyCenter'],
            ['TextColor', 'Format', 'FontSize', 'Link'],
            #['Smiley', 'Image', 'Iframe'],
            ['Image', 'Smiley', 'Iframe'],
            ['RemoveFormat', 'Source'],
        ],
        'stylesSet':[
        ],
    },
        'special':{
        'toolbar':'Special',
 #You can change this based on your requirements.
        'width': '100%',
        'height':'350',
        'toolbar_Special':[
        # ['Bold','CodeSnippet'],
        ['Bold', 'Italic', 'Underline'],
            ['NumberedList', 'BulletedList', '-', 'OutIdent', 'Ident', '-', 'JustifyLeft', 'JustifyRight', 'JustifyCenter'],
            ['TextColor', 'Format', 'FontSize', 'Link'],
            #['Smiley', 'Image', 'Iframe'],
            ['Image', 'Smiley', 'Iframe'],
            ['RemoveFormat', 'Source'],
              ['CodeSnippet'],
              ['CodeSnippet'],
        ],
        'extraPlugins':'codesnippet',
    }
}

#configuracion basica de ckeditor
# CKEDITOR_CONFIGS = {
#     'default': {
#         'toolbar': 'full',
#     },
# }


#configuracion de QUILL

# QUILL_CONFIGS = {
#     'default':{
#         'theme': 'snow',
#         'modules': {
#             'syntax': True,
#             'toolbar': [
#                 ['bold', 'italic', 'underline', 'strike'], 
#                 ['blockquote', 'code-block', 'link'],

#                 [{ 'header': 1 }, { 'header': 2 }, { 'header': 3 }],
#                 [{ 'list': 'ordered'}, { 'list': 'bullet' }],
#                 [{ 'script': 'sub'}, { 'script': 'super' }],
#                 [{ 'indent': '-1'}, { 'indent': '+1' }],
#                 [{ 'direction': 'rtl' }],

#                 [{ 'size': ['small', True, 'large', 'huge'] }],
#                 [{ 'header': [1, 2, 3, 4, 5, 6, False] }],

#                 [{ 'color': [] }, { 'background': [] }],
#                 [{ 'font': [] }],
#                 [{ 'align': [] }],

#                 ['clean']
#             ]
#         }
#     }
# }


# EMAIL SETTINGS
# EMAIL_USE_TLS = True
# EMAIL_HOST = 'smtp.gmail.com'
# EMAIL_HOST_USER = get_secret('EMAIL')
# EMAIL_HOST_PASSWORD = get_secret('PASS_EMAIL')
# EMAIL_PORT = 587

 

urls.py

"""
Proyecto Curso Django
"""
from django.contrib import admin
from django.urls import path, re_path, include

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path('', include('applications.users.urls')),
    re_path('', include('applications.home.urls')),
    re_path('', include('applications.entrada.urls')),
    re_path('', include('applications.favoritos.urls')),
    # urls para ckeditor
    re_path(r'^ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)