Django自定义模板标签在javascript [英] Django custom template tags in javascript
问题描述
我有一个自定义模板标签,如果作为学生的参数ID传递,则返回假设学生姓名和卷号。
@ register.inclusion_tag('snippet / student_name.html')
def st_name_tag(profile,disp_roll = disp_name = True):
#some计算
返回{'full_name':student.name,
'roll':student.roll_number,
}
模板(包括)由一行Html文件组成,用一行写(避免 JS函数 我的JS看起来像: 到目前为止,我尝试了上述方法,同时删除 您正在尝试根据用户的交互渲染模板。第一个发生在服务器(服务器端,通常被称为),后者发生在用户的浏览器上。 这些发生的顺序首先是在服务器上呈现模板,在浏览器中发送和显示,然后用户与js进行交互。因为这个事实,正如我在评论中提到的,不可能影响在javascript中呈现的模板。 我建议您使用 jax ,以实现此目的。无论何时发生迭代,您将异步地向服务器发出请求,向您呈现新数据。 I have a custom template tag that returns suppose name of a student and roll number if passed as an argument id of the student. The template(included) consists of some Html file which is written in a single line(to avoid I simply want to call the My JS looks like: So far I tried the above method along with removing the You are trying to render a template based on the interaction by user. The first happens on the server (server-side as it is often referred to), and the latter happens on the user's browser. The order that these happen is first to render the template on server, send and present in browser, then user interacts with js. Because of this fact, as I mentioned in the comment, it is not possible to affect the template rendered within javascript. I would recommend you to use ajax in order to accomplish this. Whenever an iteraction occurs, you asynchronously make a request to the server to present you with new data. 这篇关于Django自定义模板标签在javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! unterminated string我只想从里面调用
st_name_tag
{% load profile_tag%}
< script type =text / javascript>
eventclick:function(st){
var div =('< div>< / div>');
var st_id = st.id;
if(st.status =='pass'){
div.append('< p>学生名称:{%st_name_tag'+ st_id +'%}< / p>');
}
}
+
和''
标志从 st_id
varaible。这没有帮助我。帮助请!
@register.inclusion_tag('snippet/student_name.html')
def st_name_tag(profile, disp_roll=True, disp_name=True):
#some calculations
return {'full_name':student.name,
'roll':student.roll_number,
}
unterminated string literal
error from js).st_name_tag
from inside the JS function.{% load profile_tag %}
<script type = "text/javascript">
eventclick : function(st){
var div = ('<div></div>');
var st_id = st.id;
if (st.status == 'pass'){
div.append('<p>Student Name:{% st_name_tag '+st_id+' %}</p>');
}
}
+
and ''
signs from st_id
varaible. That hasnt helped me at all. Help Please!