skip to Main Content

can somebody help me how to include a page in base html.because i just wondering whether i have to define the url and also in view.py.because all example i have checked in stackflow non is working for me because i have tried all of them.
TemplateDoesNotExist at /

includes/footer.html

Request Method:     GET
Request URL:    http://127.0.0.1:8000/
Django Version:     1.11
Exception Type:     TemplateDoesNotExist
Exception Value:    

includes/footer.html

Exception Location:     /usr/lib64/python2.7/site-packages/django/template/engine.py in find_template, line 148
Python Executable:  /usr/bin/python
Python Version:     2.7.13
Python Path:    

['/home/harrugg2/projects/django/membersite',
 '/usr/lib/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages']

Server time:    Thu, 27 Apr 2017 15:50:50 +0300

this my base.html

{% load staticfiles %}
<html>
    <head>
        <title>member site</title>
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
        <link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
                    <!-- Core CSS - Include with every page -->
       <link rel="stylesheet"  href="{% static 'css/bootstrap.min.css' %}">
       <link rel="stylesheet" href="{% static 'css/blog.css' %}">
        <link rel="stylesheet" href="{%static 'css/Footer.css' %}">
    </head>
    <body>
         <nav class="navbar navbar-custom">
                        <!--div class="page-header"-->
                        <div class="container-fluid">
                            <div class="navbar-header">
                                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                            <a class="navbar-brand" href="/">Member site</a>
                            </div>
                             <form class="navbar-form navbar-left">
                                        <div class="form-group">
                                          <input type="text" class="form-control" placeholder="Search">
                                        </div>
                                        <button type="submit" class="btn btn-default">Submit</button>
                             </form>
                {% if user.is_authenticated %}
                            <div class="nav navbar-nav navbar-center">
                                <ul class="nav nav-pills" role="tablist">
                                  <li role="presentation"><a href=class="glyphicon glyphicon-chat>Messages <span class="badge">3</span></a></li>
                                </ul>
                            </div>     
                            <div class="nav navbar-nav navbar-center">Hello Welcome {{ user.username }} </div>                               
                            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                                <ul class="nav navbar-nav navbar-right">                                    
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">More Functions
                                            <span class="caret"></span>
                                        </a>
                                        <ul class="dropdown-menu" role="menu">
                                            <li>
                                                <a href="{% url 'post_new' %}">Add New Post</a>
                                            </li>
                                            <li>
                                                <a href="{% url 'post_draft_list' %}">Post Draft list</a>
                                            </li>
                                            <li>
                                                <a href="{% url 'profile' %}">Profile Settings</a>
                                            </li>
                                            <li class="divider"></li>
                                            <li>
                                                <a href="#">Separated link</a>
                                            </li>
                                            <li class="divider"></li>
                                            <li>
                                                <a href="{% url 'logout' %}">Logout</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </div>
                        </div>
                {% else %}
                        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                                <ul class="nav navbar-nav navbar-right">                                    
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Login
                                            <span class="caret"></span>
                                        </a>
                                        <ul class="dropdown-menu" role="menu">
                                            <li>
                                                <a href="{% url 'login' %}"><span class="glyphicon glyphicon-lock"></span>login Here</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </div>
                {% endif %}
                    </nav>
            <div class="content container">
            <div class="row">
                <div class="col-md-8">
                {% block content %}
                {% endblock %}

                    <!-- Core Scripts - Include with every page -->
                    <script src = "{% static 'js/jquery.min.js' %}"></script>

                    <script src = "{% static 'js/bootstrap.min.js' %}"></script>

                {% block javascript %}
                {% endblock %} 

                </div>
            </div>
        </div>  
        <!--footer region --> 
    <footer>
      <a href="{% include "includes/footer.html" %}"></a>
    </footer>       
    </body>
 </html>

this my footer.html

{% extends 'blog/base.html' %}
{% block content %}
<div class="content">
</div>
    <footer id="myFooter">
        <div class="container">
            <div class="row">
                <div class="col-sm-3 myCols">
                    <h5>Get started</h5>
                    <ul>
                        <li><a href="#">Home</a></li>
                        <li><a href="#">Sign up</a></li>
                        <li><a href="#">Downloads</a></li>
                    </ul>
                </div>
                <div class="col-sm-3 myCols">
                    <h5>About us</h5>
                    <ul>
                        <li><a href="#">Company Information</a></li>
                        <li><a href="#">Contact us</a></li>
                        <li><a href="#">Reviews</a></li>
                    </ul>
                </div>
                <div class="col-sm-3 myCols">
                    <h5>Support</h5>
                    <ul>
                        <li><a href="#">FAQ</a></li>
                        <li><a href="#">Help desk</a></li>
                        <li><a href="#">Forums</a></li>
                    </ul>
                </div>
                <div class="col-sm-3 myCols">
                    <h5>Legal</h5>
                    <ul>
                        <li><a href="#">Terms of Service</a></li>
                        <li><a href="#">Terms of Use</a></li>
                        <li><a href="#">Privacy Policy</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="social-networks">
            <a href="#" class="twitter"><i class="fa fa-twitter"></i></a>
            <a href="#" class="facebook"><i class="fa fa-facebook-official"></i></a>
            <a href="#" class="google"><i class="fa fa-google-plus"></i></a>
        </div>
        <div class="footer-copyright">
            <p>© 2017 Copyright Text </p>
        </div>
    </footer>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
{% include "includes/footer.html" %}    
{% endblock %}

the project layout

├── blog
│   ├── admin.py
│   ├── admin.pyc
│   ├── apps.py
│   ├── forms.py
│   ├── forms.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0001_initial.pyc
│   │   ├── 0002_comment.py
│   │   ├── 0002_comment.pyc
│   │   ├── 0003_auto_20170222_1938.py
│   │   ├── 0003_auto_20170222_1938.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   └── static
│   │       ├── css
│   │       │   ├── blog.css
│   │       │   └── bootstrap.min.css
│   │       └── js
│   │           ├── bootstrap.min.js
│   │           └── jquery.min.js
│   ├── models.py
│   ├── models.pyc
│   ├── static
│   │   ├── css
│   │   │   ├── blog.css
│   │   │   ├── bootstrap.min.css
│   │   │   └── footer.css
│   │   └── js
│   │       ├── bootstrap.min.js
│   │       └── jquery.min.js
│   ├── templates
│   │   ├── blog
│   │   │   ├── add_comment_to_post.html
│   │   │   ├── base.html
│   │   │   ├── includes
│   │   │   │   ├── footer.html
│   │   │   │   ├── footer.php
│   │   │   │   └── sidebar.html
│   │   │   ├── post_detail.html
│   │   │   ├── post_draft_list.html
│   │   │   ├── post_edit.html
│   │   │   └── post_list.html
│   │   └── registration
│   │       ├── change_password.html
│   │       ├── edit_profile.html
│   │       ├── login.html
│   │       ├── logout.html
│   │       ├── profile.html
│   │       ├── register.html
│   │       └── success.html
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   └── views.pyc
├── chat
│   ├── admin.py
│   ├── admin.pyc
│   ├── apps.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   └── views.py
├── database
│   └── dump.sql
├── data.json
├── db.sqlite3
├── manage.py
├── membersite
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── middleware.py
│   ├── middleware.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
└── README.md

this setting.py

"""
Django settings for membersite project.

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'pl&$yewh^89&^af=hgchr!4$8k&dv^gkluc(ndj3j&4$blks8s'

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

ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',

]

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',
    #'membersite.middleware.LoginRequiredMiddleware',
]

ROOT_URLCONF = 'membersite.urls'

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

WSGI_APPLICATION = 'membersite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases   
# Password validation
# https://docs.djangoproject.com/en/1.10/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.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Africa/Nairobi'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#LOGIN_REDIRECT_URL = '/account/'
#LOGIN_REDIRECT_URL = '/base/'
LOGIN_REDIRECT_URL = '/'
#LOGIN_REDIRECT_URL = 'base_url'
#LOGIN_REDIRECT_URL = '/templates/blog/base.html/'
#BASE_REDIRECT_URL = '/templates/blog/base.html/'
#BASE_REDIRECT_URL = '/account/'
#BASE_DIR = '/templates/blog/base.html/'
#LOGIN_URL = '/blog/base.html/'
LOGIN_URL = '/account/login/'
#LOGIN_URL = '/account/'
#LOGIN_URL = '/'
LOGIN_EXEMPT_URL = (
    r'^account/logout/$',
    r'^account/register/$'
    )

EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

4

Answers


  1. Change your include to following:

    <div class="footer">
     {% include "includes/footer.html" %}    
    </div>
    
    Login or Signup to reply.
  2. Your template appears to be in ‘blog/includes/footer.html’; you should use that in your include tag.

    Login or Signup to reply.
  3. You’re including footer.html in footer.html. Don’t do that.

    Login or Signup to reply.
  4. I’m unable to comment because of low rep, however i believe the runtime error you’re receiving is because you have both:

    • {% include "includes/footer.html" %} (in your base.html)
    • {% extends 'blog/base.html' %} (in your footer.html)

    This setup seems to initiate a circular dependency issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search