1
I’m trying to create blocks within my base template (index.html), but apparently the block is not used.
index.html
{% load static %}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Portfolio's</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{% static 'content/css/bootstrap.css' %}">
<link href="https://fonts.googleapis.com/css?family=Lobster|Oswald|Port+Lligat+Slab" rel="stylesheet">
.
.
.
<div class='container'>
<div class='row'>
<div id='artigo' class='col-lg-8'>
{% block corpo_artigo %}
{% endblock %}
.
.
.
When I call it in a separate file, it is not effective
corpo_article.html
{% extends "index.html" %}
{% block corpo_artigo %}
{% for item in conteudo_artigo%}
{% if item.photo %}
<img src="{{item.photo}}" class="img-responsive" alt="...">
{% endif %}
<a id='titulo' href="/artigos/{{item.id}}"><h1>{{item.titulo}}</h1></a>
<h5 id ='autor'>{{item.autor}}</h5>
<h5 id ='tag'>{{item.tag}}</h5>
{% if item.corpo|length > 1000 %}
<p id = 'corpo_artigo'>{{item.corpo|truncatewords:200|safe}}</p>
<button class="btn btn-default navbar-btn"> <a href="/artigos/{{item.id}}">Continue lendo</a></button>
{% else %}
<p>{{item.corpo}}</p>
{% endif%}
<h5 id ='data'>{{item.data}}</h5>
{% endfor %}
{% endblock %}
Obs I’m using a directory called templates using:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
EDIT: I noticed that the {% extends "index.html"%} tag works normally, but everything I put inside {% block % doesn’t work.
Why would you be using a style tag inside a block ? wouldn’t it be easier just to call the style sheet ? in Django just create a folder named Static and place the stylesheet there then create olink for it in html using <link rel="stylesheet" type="text/css" href="{% Static 'style.css' %}" />
– user73316
Yes, I guess I wasn’t very happy with my example. I actually know about this feature, but the problem persists with whichever element I put inside a block.
– Otávio Reis Perkles
can inform if there is an error ? or just does not appear the template ?
– user73316
The template simply does not appear. If I only use {% extends "index.html" %} it extends the code of the index page, but if I put something inside a block it does not display.
– Otávio Reis Perkles