Andrew Nguyen
Andrew Nguyen

Reputation: 1436

Trouble with "extends" can be only used once in Django template

I originally thought I would use {% extends ["filename.html"] %} to take html I've written in a template and put it into my main file, but since you can only use "extends" once, how can I have it so that my sidebar.html and slider.html are like snippets that can be put into my main html file, which I've called list.html

Here's an image of what things look like now: http://imgur.com/K5XKAcQ Here's an image of the error: http://imgur.com/Uqs3iQo

Upvotes: 0

Views: 125

Answers (3)

alacy
alacy

Reputation: 5074

You can use an include statement. Also, see here.

Upvotes: 0

JBux
JBux

Reputation: 1394

You can use include in the main template

Rather than adding a tag in the sidebar.html, in filename.html, add:

{% include "sidebar.html" %}

Upvotes: 0

swstephe
swstephe

Reputation: 1910

Use "extends" like referencing a base class. Multiple-inheritance isn't supported (directly). To include snippets of code in your content, use "include":

{% extends "layout.html" %}
{% include "sidebar.html" %}
{% include "slider.html" %}

See: https://docs.djangoproject.com/en/dev/ref/templates/builtins/

Upvotes: 4

Related Questions