-1
请让我知道在Django中如何调用从模板HTML写的方法来查看。 也请告诉我如何传递变量。如何从模板调用函数使用Django
class index(TemplateView):
template_name = "index.html"
def get(self, request, *args, **kwargs):
text = "text"
return render(request, self.template_name, {'text': text})
def Replace
text = "Replaced"
(I want to pass variable text to index html from here)
index.html的是如下
<p>{{ text }}<p>
<a html="{?????}">text replace</>
如果单击“文本替换”你要调用的函数“替换”,以取代变量“文本”。 虽然这是一个基本的问题,谢谢。
如果您只想替换某个标签中的文本,为什么不使用ajax? –
问题代码只是一个例子,我想用函数替换变量并将变量传递给template.Without使用ajax。 – xKxAxKx
那么你想要在客户端执行该功能(由任何用户的操作启动)还是在渲染模板时执行? –