Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将javascript添加到django中块内容的change_form.html中_Python_Django - Fatal编程技术网

Python 如何将javascript添加到django中块内容的change_form.html中

Python 如何将javascript添加到django中块内容的change_form.html中,python,django,Python,Django,我想向模型的change_form.html模板添加一个javascript,该模板继承自django管理员的模板。我想根据登录类型显示/显示模型的一些属性。用户可以是客户或员工组成员。有人能指引吗?如何在change\u form.html的{%block content%}标记中使用它您不需要内容块,有头块,您可以将js放在那里。但是js阻止某些用户修改某些字段的功能很容易被黑客攻击 {% block extrahead %} {{ block.super }} <s

我想向模型的change_form.html模板添加一个javascript,该模板继承自django管理员的模板。我想根据登录类型显示/显示模型的一些属性。用户可以是客户或员工组成员。有人能指引吗?如何在change\u form.html的{%block content%}标记中使用它

您不需要
内容
块,有
块,您可以将js放在那里。但是js阻止某些用户修改某些字段的功能很容易被黑客攻击

{% block extrahead %}
    {{ block.super }}

    <script type="text/javascript">
        $(function() {
            {% if user.get_profile.is_customer %}
                $('#id_of_field_block').hide();
            {% endif %}
        });
    </script>
{% endblock extrahead %}
{%block extrahead%}
{{block.super}}
$(函数(){
{%if user.get_profile.is_customer%}
$(“#id_of_field_block”).hide();
{%endif%}
});
{%endblock extrahead%}

您还可以更改
change_form.html
模板并覆盖
内容
块,将原始文件内容作为源文件,并更改字段集模板
fieldset.html
(或者您可以只覆盖fieldset.html,我不确定)。此模板在字段上迭代,您可以在其中添加一些检查。

您不需要
内容
块,有
块,您可以将js放在那里。但是js阻止某些用户修改某些字段的功能很容易被黑客攻击

{% block extrahead %}
    {{ block.super }}

    <script type="text/javascript">
        $(function() {
            {% if user.get_profile.is_customer %}
                $('#id_of_field_block').hide();
            {% endif %}
        });
    </script>
{% endblock extrahead %}
{%block extrahead%}
{{block.super}}
$(函数(){
{%if user.get_profile.is_customer%}
$(“#id_of_field_block”).hide();
{%endif%}
});
{%endblock extrahead%}

您还可以更改
change_form.html
模板并覆盖
内容
块,将原始文件内容作为源文件,并更改字段集模板
fieldset.html
(或者您可以只覆盖fieldset.html,我不确定)。此模板在字段上迭代,您可以在其中添加一些检查。

我们确实需要在extrahead块中添加js,但我想基于登录显示/隐藏一些模型属性。让我使用div id尝试show()和hide()函数。我们确实需要在extrahead块中添加js,但是我想基于login显示/隐藏一些模型属性。让我用div id尝试show()和hide()函数