python - Django variable not visible in header section -


i have basic start blog, lists out blog articles database in post_list.html extends header.html. trying variable in header slogan not working.

header.html - renders without "propaganda.slogan" entered admin pages , has content:

<!doctype html>   <html lang="en">   <head>     <title>hey!</title>     <meta charset="utf-8" />     {% load staticfiles %}     <link rel="stylesheet" href="{% static 'blog/css/bulma.css' %}"      type="text/css"/>    </head>       <body>     <section class="hero is-success is-bold">         <div class="hero-body">             <div class="container">                 {% block slogan %}                     <ul>                     {% propaganda in propagandas %}                         <li>{{ propaganda.slogan }}</li>                     {% endfor %}                     </ul>                        {% endblock %}                 <h1 class="title">                     weblog                 </h1>             </div>         </div>     </section>     {% block content %}     {% endblock %} </body> </html> 

post_list.html extends header.html , displays list of posts models.py:

{% extends "blog/header.html" %} {% block content %}     {% post in posts %}         <section class="section">             <div class="container">                 <h1 class="title"><a href="#">{{ post.title }}</a></h1>                 <p>{{ post.summary|linebreaksbr }}</p>                 <p>published: {{ post.last_edited }}</p>             </div>         </section>     {% endfor %}     {% endblock %} 

models.py looks this:

from django.db import models django.utils import timezone  # create models here. class propaganda(models.model):     slogan = models.charfield(max_length=140, blank=true, null=true)      def __str__(self):         return self.slogan   class post(models.model):     title = models.charfield(max_length=140, blank=false, null=false)     content = models.textfield()     summary = models.charfield(max_length=500)     created_date = models.datetimefield()     last_edited = models.datetimefield()      def __str__(self):         return self.title 

finally, views.py is:

from django.shortcuts import render .models import post, propaganda  # create views here. def post_list(request):     posts = post.objects.all()     return render(request, 'blog/post_list.html', {'posts': posts})  def header(request):     propagandas = propaganda.objects.all()     return render(request, 'blog/header.html', {'propagandas': propagandas}) 

so why can list of post titles, summary , date in post_list.html can't list of propagandist slogans in header?

to me looks same code, almost?

i no error dev server or in browser :(

you'll need pass list of propagnadas context of current template; including template has little or nothing associated (if makes sense in first place) view of included template:

def post_list(request):     posts = post.objects.all()     propagandas = propaganda.objects.all()     return render(request, 'blog/post_list.html', {'posts': posts, 'propagandas': propagandas}) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -