[英]Django variable in base.html
base.html
is used as the base template for all other pages. base.html
用作所有其他页面的基本模板。 base.html
has the navigation bar and in the navigation bar, I want to show the number of messages the user received. base.html
有导航栏,在导航栏中,我想显示用户收到的消息数。 Thus, I need to have a variable like {{number_of_messages}}
in the base.html
.因此,我需要在base.html
有一个像{{number_of_messages}}
这样的变量。
However, how should I pass this variable to it?但是,我应该如何将这个变量传递给它? Every template extends base.html
and is rendered by a function.每个模板都扩展了base.html
并由一个函数呈现。 I don't think returning number_of_messages
in all functions is a good way.我不认为在所有函数中返回number_of_messages
是一个好方法。 Is there better way to implement this?有没有更好的方法来实现这一点? How can I pass this variable to all templates?如何将此变量传递给所有模板?
base.html
is used as the base template for all other pages. base.html
用作所有其他页面的基本模板。 base.html
has the navigation bar and in the navigation bar, I want to show the number of messages the user received. base.html
有导航栏,在导航栏中,我想显示用户收到的消息数。 Thus, I need to have a variable like {{number_of_messages}}
in the base.html
.因此,我需要在base.html
有一个像{{number_of_messages}}
这样的变量。
However, how should I pass this variable to it?但是,我应该如何将这个变量传递给它? Every template extends base.html
and is rendered by a function.每个模板都扩展了base.html
并由一个函数呈现。 I don't think returning number_of_messages
in all functions is a good way.我不认为在所有函数中返回number_of_messages
是一个好方法。 Is there better way to implement this?有没有更好的方法来实现这一点? How can I pass this variable to all templates?如何将此变量传递给所有模板?
base.html
is used as the base template for all other pages. base.html
用作所有其他页面的基本模板。 base.html
has the navigation bar and in the navigation bar, I want to show the number of messages the user received. base.html
有导航栏,在导航栏中,我想显示用户收到的消息数。 Thus, I need to have a variable like {{number_of_messages}}
in the base.html
.因此,我需要在base.html
有一个像{{number_of_messages}}
这样的变量。
However, how should I pass this variable to it?但是,我应该如何将这个变量传递给它? Every template extends base.html
and is rendered by a function.每个模板都扩展了base.html
并由一个函数呈现。 I don't think returning number_of_messages
in all functions is a good way.我不认为在所有函数中返回number_of_messages
是一个好方法。 Is there better way to implement this?有没有更好的方法来实现这一点? How can I pass this variable to all templates?如何将此变量传递给所有模板?
base.html
is used as the base template for all other pages. base.html
用作所有其他页面的基本模板。 base.html
has the navigation bar and in the navigation bar, I want to show the number of messages the user received. base.html
有导航栏,在导航栏中,我想显示用户收到的消息数。 Thus, I need to have a variable like {{number_of_messages}}
in the base.html
.因此,我需要在base.html
有一个像{{number_of_messages}}
这样的变量。
However, how should I pass this variable to it?但是,我应该如何将这个变量传递给它? Every template extends base.html
and is rendered by a function.每个模板都扩展了base.html
并由一个函数呈现。 I don't think returning number_of_messages
in all functions is a good way.我不认为在所有函数中返回number_of_messages
是一个好方法。 Is there better way to implement this?有没有更好的方法来实现这一点? How can I pass this variable to all templates?如何将此变量传递给所有模板?
base.html
is used as the base template for all other pages. base.html
用作所有其他页面的基本模板。 base.html
has the navigation bar and in the navigation bar, I want to show the number of messages the user received. base.html
有导航栏,在导航栏中,我想显示用户收到的消息数。 Thus, I need to have a variable like {{number_of_messages}}
in the base.html
.因此,我需要在base.html
有一个像{{number_of_messages}}
这样的变量。
However, how should I pass this variable to it?但是,我应该如何将这个变量传递给它? Every template extends base.html
and is rendered by a function.每个模板都扩展了base.html
并由一个函数呈现。 I don't think returning number_of_messages
in all functions is a good way.我不认为在所有函数中返回number_of_messages
是一个好方法。 Is there better way to implement this?有没有更好的方法来实现这一点? How can I pass this variable to all templates?如何将此变量传递给所有模板?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.