开发者

The same data in all django templates

开发者 https://www.devze.com 2023-03-21 21:51 出处:网络
I have created my text based game and my game pages have structure like this: {% extends \'base.html\' %}

I have created my text based game and my game pages have structure like this:

{% extends 'base.html' %}
{% block content %}
// content
{% include 'links.html' %}
{开发者_运维问答% endblock %}

Now I'm thinking about notifying players about a new message at the top of every page, so I have to update only base.html to show the information, however, I have to add data about new messages to every template before rendering. Maybe is there a quicker way to do that?


You probably want to look into Context Processors -> docs. That's how you automatically add stuff to your templates. Here's a detailed example -- it's old, but I think it still works.

Or you can just use the messages framework, which has the appropriate Context Processor implemented and should do what you need here.

0

精彩评论

暂无评论...
验证码 换一张
取 消