Template inheritance not working

32 views
Skip to first unread message

Alec Delaney

unread,
Oct 31, 2022, 2:09:32 PM10/31/22
to django...@googlegroups.com
I have been trying to get my templates to work but they have been ineffective. here is my code:
{% extends "index.html" %}

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<div>
{% block content %}


{% endblock %}
</div>
</body>
</html>

//index.html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    {% block content %}
        <h1>Hello, this is a test.</h1>
        <p>Help me.</p>
    {% endblock %}
</body>
</html>

Ammar Mohammed

unread,
Oct 31, 2022, 2:34:37 PM10/31/22
to 'Rahul Chauhan' via Django users
Hello dear 
There is a little mistake in your code :
You should put the {%block block_name %} in your base template with no code and the put the code you want to be displayed in your child template file
Here is an example : 

// file.html :

{% extends "index.html" %}

{% block content %}
<h1>Hello, this is a test.</h1>
    <p>Help me.</p>
{% endblock %}

//index.html:
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    {% block content %}
       
    {% endblock %}
</body>
</html>


-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFGN%3DGjpkAW6NBXLZ%3DYL7eXy3FXmJ6DqWfNMh%2BikMrp7om361Q%40mail.gmail.com.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFGN%3DGjpkAW6NBXLZ%3DYL7eXy3FXmJ6DqWfNMh%2BikMrp7om361Q%40mail.gmail.com.

FLAVIEN HERI

unread,
Nov 2, 2022, 5:26:42 AM11/2/22
to django...@googlegroups.com
can it be the problem of the first block content which is empty.in
index.html, try to delete the empty block content, leave the second
one and see what happen
> <https://groups.google.com/d/msgid/django-users/CAFGN%3DGjpkAW6NBXLZ%3DYL7eXy3FXmJ6DqWfNMh%2BikMrp7om361Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>> <https://groups.google.com/d/msgid/django-users/CAFGN%3DGjpkAW6NBXLZ%3DYL7eXy3FXmJ6DqWfNMh%2BikMrp7om361Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHs1H7sS6tndz4j8wiK_Dfpwqnb7sUcrc814Zp3eTndDJ%2B5Ewg%40mail.gmail.com.
>


--
FLAVIEN HERI

*Information management AscociateUNHCR-Kinshasa*
Tél:+243978587009
Skype: flavien.heri1
Facebook: flavien semi

peteru mimo

unread,
Nov 2, 2022, 5:52:09 AM11/2/22
to django...@googlegroups.com
Your template inheritance cannot be index.html make it base.html and put whatever you want to be display in all pages on it then extends it in index page and other page

subin

unread,
Nov 3, 2022, 3:45:00 PM11/3/22
to django...@googlegroups.com

subin

unread,
Nov 3, 2022, 3:45:35 PM11/3/22
to django...@googlegroups.com
Thanks for contacting XYZ Company! One of our sales reps will reach out to you shortly. Tap to browse our summer sale while you wait

On Wed, Nov 2, 2022 at 10:26 AM FLAVIEN HERI <flavie...@gmail.com> wrote:

subin

unread,
Nov 3, 2022, 4:44:04 PM11/3/22
to django...@googlegroups.com
I will look forward to meeting you on July 11

subin

unread,
Nov 3, 2022, 4:45:17 PM11/3/22
to django...@googlegroups.com
Hope you had a good time.

Alec Delaney

unread,
Nov 8, 2022, 8:48:33 PM11/8/22
to django...@googlegroups.com

Alec Delaney

unread,
Nov 18, 2022, 3:54:34 PM11/18/22
to django...@googlegroups.com
Hello. How are you? Can I see another example of template inheritance?

On Mon, Oct 31, 2022 at 2:34 PM Ammar Mohammed <amarb...@gmail.com> wrote:

David Emanuel Sandoval

unread,
Nov 18, 2022, 4:01:57 PM11/18/22
to django...@googlegroups.com
The base template contains the default content, and blocks with default contents in it. Then, in the child template, you can override those blocks.

Chukwudi Onwusa

unread,
Nov 18, 2022, 10:04:22 PM11/18/22
to django...@googlegroups.com
What error is it showing you?
Please send a picture of it. Remember you can save your base with your desired name, but you should also not that you should register your templates directory in settings template list as [BASE_DIRS/ "templates"] and Incase your template files are in an embedded directory inside your templates directory, kindly do well to correct it as "embeddedDirectory/baseName.html" and also correct your views for other templates references too if need be.
Thanks.
Best Regards.

Alec Delaney

unread,
Nov 19, 2022, 11:15:36 AM11/19/22
to django...@googlegroups.com
Hello, would you be available for zoom?


Chukwudi Onwusa

unread,
Nov 19, 2022, 11:53:52 AM11/19/22
to django...@googlegroups.com

Alec Delaney

unread,
Nov 19, 2022, 12:10:44 PM11/19/22
to django...@googlegroups.com
you dont have zoom?


On Sat, Nov 19, 2022 at 12:09 PM Alec Delaney <96alec...@gmail.com> wrote:
Okay, Cause I am looking for another example for template inheritance


Alec Delaney

unread,
Nov 19, 2022, 12:10:45 PM11/19/22
to django...@googlegroups.com
Okay, Cause I am looking for another example for template inheritance


On Sat, Nov 19, 2022 at 11:54 AM Chukwudi Onwusa <chuks...@gmail.com> wrote:

subin

unread,
Nov 19, 2022, 12:26:47 PM11/19/22
to django...@googlegroups.com

subin

unread,
Nov 19, 2022, 12:27:16 PM11/19/22
to django...@googlegroups.com
Season’s greetings! Our offices will be closed on Dec. 24 and 25. However

subin

unread,
Nov 19, 2022, 12:27:55 PM11/19/22
to django...@googlegroups.com
I will continue learning more about .

subin

unread,
Nov 19, 2022, 12:28:44 PM11/19/22
to django...@googlegroups.com

subin

unread,
Nov 19, 2022, 12:36:20 PM11/19/22
to django...@googlegroups.com
I will continue learning more about .

subin

unread,
Nov 19, 2022, 12:57:40 PM11/19/22
to django...@googlegroups.com
Thank you for reaching out to us

subin

unread,
Nov 19, 2022, 12:58:58 PM11/19/22
to django...@googlegroups.com

Chukwudi Onwusa

unread,
Nov 19, 2022, 1:47:03 PM11/19/22
to django...@googlegroups.com
You can WhatsApp me on 08125409314, screenshot short your error page and send, together with with inherited template and your parent template.

subin

unread,
Nov 19, 2022, 1:58:41 PM11/19/22
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages