Template inheritance not working

32 vues
Accéder directement au premier message non lu

Alec Delaney

non lue,
31 oct. 2022, 14:09:3231/10/2022
à 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

non lue,
31 oct. 2022, 14:34:3731/10/2022
à '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

non lue,
2 nov. 2022, 05:26:4202/11/2022
à 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

non lue,
2 nov. 2022, 05:52:0902/11/2022
à 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

non lue,
3 nov. 2022, 15:45:0003/11/2022
à django...@googlegroups.com

subin

non lue,
3 nov. 2022, 15:45:3503/11/2022
à 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

non lue,
3 nov. 2022, 16:44:0403/11/2022
à django...@googlegroups.com
I will look forward to meeting you on July 11

subin

non lue,
3 nov. 2022, 16:45:1703/11/2022
à django...@googlegroups.com
Hope you had a good time.

Alec Delaney

non lue,
8 nov. 2022, 20:48:3308/11/2022
à django...@googlegroups.com

Alec Delaney

non lue,
18 nov. 2022, 15:54:3418/11/2022
à 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

non lue,
18 nov. 2022, 16:01:5718/11/2022
à 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

non lue,
18 nov. 2022, 22:04:2218/11/2022
à 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

non lue,
19 nov. 2022, 11:15:3619/11/2022
à django...@googlegroups.com
Hello, would you be available for zoom?


Chukwudi Onwusa

non lue,
19 nov. 2022, 11:53:5219/11/2022
à django...@googlegroups.com

Alec Delaney

non lue,
19 nov. 2022, 12:10:4419/11/2022
à 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

non lue,
19 nov. 2022, 12:10:4519/11/2022
à 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

non lue,
19 nov. 2022, 12:26:4719/11/2022
à django...@googlegroups.com

subin

non lue,
19 nov. 2022, 12:27:1619/11/2022
à django...@googlegroups.com
Season’s greetings! Our offices will be closed on Dec. 24 and 25. However

subin

non lue,
19 nov. 2022, 12:27:5519/11/2022
à django...@googlegroups.com
I will continue learning more about .

subin

non lue,
19 nov. 2022, 12:28:4419/11/2022
à django...@googlegroups.com

subin

non lue,
19 nov. 2022, 12:36:2019/11/2022
à django...@googlegroups.com
I will continue learning more about .

subin

non lue,
19 nov. 2022, 12:57:4019/11/2022
à django...@googlegroups.com
Thank you for reaching out to us

subin

non lue,
19 nov. 2022, 12:58:5819/11/2022
à django...@googlegroups.com

Chukwudi Onwusa

non lue,
19 nov. 2022, 13:47:0319/11/2022
à 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

non lue,
19 nov. 2022, 13:58:4119/11/2022
à django...@googlegroups.com
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message