简体   繁体   English

比较django变量和角度变量

[英]compare django variable with angular variable

I am using django backend and angular for frontend. 我正在使用django后端和angular的前端。 Now i am facing an issue which is i need to compare a variable value which comes from django view with another variable value which comes from angular. 现在我面临的一个问题是,我需要将来自django视图的变量值与来自角度的另一个变量值进行比较。 im doing this following simple way but it is not working. 我按照下面的简单方法做,但是没有用。 please suggest how to do this. 请建议如何执行此操作。

{% for item in items %}
    {% if item.employee_id == {% verbatim %}{{ interview._source.employee.id }}{% endverbatim %}  %}
            something here
    {% else %}
        something here

No , I don't think its possible to compare the angularjs variable with a Django variable in the Django template. ,我认为不可能将Django模板中的angularjs变量与Django变量进行比较。

This is because all the variables and template tags are computed on the server side while angularjs is rendered on the client side. 这是因为所有变量和模板标记都是在服务器端计算的,而angularjs是在客户端渲染的。

You won't have access to the angularjs variable until that variable is generated on the client side. 在客户端上生成该变量之前,您将无法访问angularjs变量。

Solution: 解:

A possible solution is to calculate and compare the variable on the server side in the Django code ie move the comparison logic to Django code if possible. 一个可能的解决方案是在Django代码的服务器端计算和比较变量,即,如果可能,将比较逻辑移到Django代码。

You need to swap your logic around. 您需要交换逻辑。 There is no possible way for Django templates to be aware of Angular variables, and it really should be clear why. 没有为Django模板要注意角度的变量没有可能的方式 ,它真的应该很清楚为什么。

Instead, you'll need to output everything you need in the template, and use Angular code to do the comparison. 相反,您需要输出模板中所需的所有内容,并使用Angular代码进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM