开发者

The same data in all django templates

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜