# Flatpages on localhost

**URL:** <https://forum.djangoproject.com/t/flatpages-on-localhost/2310>\
**Category:** Using Django\
**Created:** [May 7, 2020, 5:35pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310 "2020-05-07T17:35:16Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 5:35pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/1 "2020-05-07T17:35:16Z")

</div>

I would like to work with flatpages and so I followed the instructions and installed it correctly and I can see the flatpage in admin and also the sites. As default there is an [example.com](http://example.com) site and if you choose that and you want to view the page it takes you to example site with the url of your page you created

How can I view the page on my local machine and localhost because [http://localhost:8000/about/](http://localhost:8000/about/) does not work and I cannot see the about page I created in admin?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 7, 2020, 5:52pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/2 "2020-05-07T17:52:38Z")

</div>

We’d probably need to see at least your settings file (any sensitive information redacted) and your urls.py file(s) associated with your app.

Also, assuming you’re using runserver in a shell session to run your application, it might be helpful to see the output from that as well.

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 5:54pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/3 "2020-05-07T17:54:53Z")

</div>

Ok here is the settings.py file

```auto
"""
Django settings for learndjango project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^82-d++=-5hqd(s5#v+(_bh-^=791lra*eb8!m_lqg9qt^ubdw'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

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',

    # own apps
    'plugins',
]

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'learndjango.wsgi.application'

SITE_ID = 1

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'trydjango',
        'USER' : 'admin',
        'PASSWORD' : '',
    }
}

# Password validation
# https://docs.djangoproject.com/en/3.0/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/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Africa/Johannesburg'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
```

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 5:55pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/4 "2020-05-07T17:55:48Z")

</div>

Here is the urls.py file

```auto
from django.contrib import admin
from django.urls import path, include
from django.contrib.flatpages import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('/', include('django.contrib.flatpages.urls')),
]
urlpatterns += [
    path('about/', views.flatpage, {'url': '/about/'}, name='about'),
]
```

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 5:57pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/5 "2020-05-07T17:57:17Z")

</div>

Here is the output and it says the template does not exist but I promise you it does

```auto
Traceback (most recent call last):
  File "/home/calvin/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/contrib/flatpages/views.py", line 45, in flatpage
    return render_flatpage(request, f)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/contrib/flatpages/views.py", line 61, in render_flatpage
    template = loader.get_template(DEFAULT_TEMPLATE)
  File "/home/calvin/.local/lib/python3.6/site-packages/django/template/loader.py", line 19, in get_template
    raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: flatpages/default.html
[07/May/2020 19:49:46] "GET /about/ HTTP/1.1" 500 84193
Not Found: /favicon.ico
```

![Selection_007](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/1675ca6d4c914819d82fdca1de69409f267d5108.png)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 7, 2020, 6:03pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/6 "2020-05-07T18:03:59Z")

</div>

So what this is telling you is that it can’t find the template. You might have that template file, but something isn’t configured correctly for that template file to be found.

In this case, you don’t have this template file in an app of yours under a templates directory (APP\_DIRS True), but you have it under a template directory in the root of your project. This means that in your DIRS entry you need to include this root template directory. Frequently, you’ll see it specified as " ‘DIRS’: [os.path.join(BASE\_DIR, ‘templates’),],

(In a couple projects, I have it as simply ‘DIRS’: [‘templates’,] )

See [Templates](https://docs.djangoproject.com/en/3.0/ref/settings/#templates)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:12pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/7 "2020-05-07T18:12:41Z")

</div>

I am all new to this so excuse my lack of knowledge. I made the change and I still get the same error but with extra things at the bottom  
`django.template.loaders.filesystem.Loader` : /flatpages/default.html (Source does not exist)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:13pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/8 "2020-05-07T18:13:38Z")

</div>

here is the settings

```auto

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',
            ],
        },
    },
]
```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 7, 2020, 6:16pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/9 "2020-05-07T18:16:56Z")

</div>

[‘DIRS’ is a list.](https://docs.djangoproject.com/en/3.0/ref/settings/#dirs) It needs to be:

```auto
‘DIRS’: [os.path.join(BASE_DIR, ‘templates’),],

```

(Don’t worry - these types of mistakes are very common when getting started - or even when you’ve been doing this for years.)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:23pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/10 "2020-05-07T18:23:21Z")

</div>

Here are the settings.py templates section now:

```auto
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',
            ],
        },
    },
]
```

here is my file structure:  
 ![Selection_008](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/0/02cdec0e7b013f63641f40f038fb34f8e0177029.png)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:26pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/11 "2020-05-07T18:26:25Z")

</div>

Not working and same messages

```auto
# TemplateDoesNotExist at /about/

flatpages/default.html

|Request Method:|GET|
| --- | --- |
|Request URL:|http://localhost:8000/about/|
|Django Version:|3.0.3|
|Exception Type:|TemplateDoesNotExist|
|Exception Value:|flatpages/default.html|
```

here is my settings.py file

```auto

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',
            ],
        },
    },
]
```

Here is my file structure now I copied the templates dir to the root and the project folder  
 ![Selection_008](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/0/02cdec0e7b013f63641f40f038fb34f8e0177029.png)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:39pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/12 "2020-05-07T18:39:15Z")

</div>

My post was hidden by akismet so I have to wait for it to be shown. I really want to learn this. Thanks for all the help. I presume your name is Ken

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 7, 2020, 6:40pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/13 "2020-05-07T18:40:37Z")

</div>

You’re certainly welcome.

Ken  
(yep, that’s my name)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [May 7, 2020, 6:44pm UTC](https://forum.djangoproject.com/t/flatpages-on-localhost/2310/14 "2020-05-07T18:44:07Z")

</div>

Happy too make your acquaintance. My name is Calvin and as you know by now I am a newbie, on a mission to learn this. Not sure how long it will take for the post to show. I will check back later.
