1

Made a cms project in django, but its not loading my default template for flatpages, attached are the images.

Thanks

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.flatpages',
]

SITE_ID = 1

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',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
]

Error page

Directory structure

Admin

Shoyeb Sheikh
  • 2,659
  • 2
  • 10
  • 19

2 Answers2

1

You need to do some changes in your settings file.

Declare a variable BASE_DIR as:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Then edit the DIRS in the TEMPLATES as:

'DIRS': [os.path.join(BASE_DIR, 'templates')],

Also keep the template files of cms inside cms folder like:

cms>templates>cms>flatpages

Sanip
  • 1,772
  • 1
  • 14
  • 29
0

Did you set the TEMPLATES in your settings.py? Check and set the TEMPLATES.DIR setting to your folder path:

TEMPLATES = {
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
}

Moreover, you can move the templates folder inside the cms folder. In this case, be sure that TEMPLATES.APP_DIRS is set to True.

cms
+- cms/
 +- templates/
  +- flatpages/
   +- default.html
 +- views.py
 +- other django stuff...
+- db.sqlite3

You can find more information in the official documentation: https://docs.djangoproject.com/en/2.1/topics/templates/#configuration

Vincent
  • 472
  • 2
  • 8