Reputation: 5507
settings.py
from .ENV import BASE_DIR, ENV_VAR
# SECURITY WARNING: don't run with debug turned on in production!
# False if not in os.environ
DEBUG = ENV_VAR('DEBUG', default=False)
# SECURITY WARNING: keep the secret key used in production secret!
# If not found in os.environ will raise ImproperlyConfigured error
SECRET_KEY = ENV_VAR('SECRET_KEY')
SITE_ID = 1
# Application definition
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',
'djangocms_style',
'djangocms_column',
'djangocms_file',
'djangocms_googlemap',
'djangocms_inherit',
'djangocms_link',
'djangocms_picture',
'djangocms_teaser',
'djangocms_video',
'reversion',
'config',
]
MIDDLEWARE_CLASSES = [
'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'
]
ROOT_URLCONF = 'urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR('config/templates'),
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
'django.core.context_processors.debug',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.csrf',
'django.core.context_processors.tz',
'sekizai.context_processors.sekizai',
'django.core.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'
],
},
},
]
WSGI_APPLICATION = 'config.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': ENV_VAR.db()
}
# Password validation
# https://docs.djangoproject.com/en/1.9/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.8/topics/i18n/
LANGUAGE_CODE = 'en'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = BASE_DIR('media', default='')
MEDIA_URL = '/media/'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR('static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
urls.py
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
admin.autodiscover()
urlpatterns = [
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
{'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^select2/', include('django_select2.urls')),
]
urlpatterns += i18n_patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
DIR Structure
.
|-- apps
| |-- __init__.py
|-- config
| |-- __init__.py
| |-- settings
| | |-- base.py
| | |-- configurations
| | | |-- DJANGOCMS.py
| | | |-- DJANGO.py
| | | |-- ENV.py
| | | |-- GRAPPELLI.py
| | | |-- __init__.py
| | |-- dev.py
| | |-- __init__.py
| | `-- pro.py
| |-- templates
| | |-- base.html
| | |-- feature.html
| | |-- menu.html
| | |-- page.html
| |-- wsgi.py
|-- manage.py
|-- media
|-- requirements
| |-- base.txt
| |-- dev.txt
| `-- pro.txt
|-- requirements.txt
|-- static
|-- urls.py
I am unable to open localhost:8000/ it always redirects me to login page. Then I have created a new project and this time kept the default project layout and now this is what I see if I open localhost:8000/
So if someone can tell me what is wrong ?? How do I use custom templates ???
Upvotes: 1
Views: 1897
Reputation: 12859
First off, if it redirects you to the login page, that'll most likely be because there isn't any content yet. Based on the question, I'm assuming this is a new installation with no pages, so you'd need to login, create your pages, and then you should get it to load without the admin redirect.
In terms of overriding templates, it works the same as for any django or app template.
If you want to use a custom template, you simply create your own version following the same path as the original, but in one of your own template directories.
For example I've got a directory in my project where I override CMS templates;
/project/myapp/templates/cms/toolbar/plugin.html
Which you can see in the CMS app lives in that same template path;
https://github.com/divio/django-cms/tree/release/3.3.x/cms/templates/cms/toolbar
If you've got templates that you wish to make available as page templates for the CMS then there is a CMS_TEMPLATES
setting which you add like so;
CMS_TEMPLATES = (
('home.html', 'Homepage'),
('article.html', 'Article'),
('blogs/entry_form.html', 'Blogs Competition Entry Form'),
)
Upvotes: 2