Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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/2/django/23.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
django:无法将jQuery库导入扩展模板_Jquery_Django - Fatal编程技术网

django:无法将jQuery库导入扩展模板

django:无法将jQuery库导入扩展模板,jquery,django,Jquery,Django,我有一个base.html模板,该模板由其他模板继承(即user\u profile.html页面),如下所示:{%extensed“base.html”%} 问题是jquery库只对base.html模板可见。放置在用户配置文件.html模板中的jQuery(document).ready(function())中的代码不会运行 如果我在user_profile.html模板中放置jQuery库的第二个导入标记,那么它自己的jQuery在ready()函数中运行正常,但是base.html看不

我有一个base.html模板,该模板由其他模板继承(即user\u profile.html页面),如下所示:
{%extensed“base.html”%}

问题是jquery库只对base.html模板可见。放置在用户配置文件.html模板中的jQuery(document).ready(function())中的代码不会运行

如果我在user_profile.html模板中放置jQuery库的第二个导入标记,那么它自己的jQuery在ready()函数中运行正常,但是base.html看不到它自己的jQuery ready()代码(尽管那里也有初始导入标记)

这就是我使用的:

(希望以上所有内容都有意义。)

我做错了什么

-编辑-

这是base.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
<head>
    <title>{% block title %} {% endblock %}</title>

    <!-- remote apis first -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>

    <!-- then local -->
    <script src="/site_media/js/ui/jquery.ui.core.js"></script>

    <script type="text/javascript">
        jQuery(document).ready(function(){
            alert('it works!'); //this alert popups normally
        });
    </script>

    {% block external %} {% endblock %}
</head>
<body id="body">
    <div id="wrap">

    <!--  same stuff for all templates is going on here -->

        <div id="content">
            <!-- main content area, different for each template-->
            <div class="main">
                 {% block maincontent %} {% endblock %}
            </div>
        </div>
    </div> <!-- wrapper -->

    {etc...}

{%block title%}{%endblock%}
jQuery(文档).ready(函数(){
警报('it works!');//此警报通常会弹出
});
{%block external%}{%endblock%}
{%block maincontent%}{%endblock%}
{等等..}
这是user_profile.html

{% extends "base.html" %}
{% load my_tags %}
{% block title %}User Home{% endblock %}

<!-- following block is inside the <head> of the base.html -->
{% block external %} 
    <link rel="stylesheet" href="/site_media/css/maps.css" type="text/css" media="screen" />
    <script type="text/javascript">
        jQuery(document).ready(function(){
            alert('hi!'); // it is never reached!
        });

    </script>
{% endblock %}

{% block maincontent %}
    <!-- stuff is going on here -->
{% endblock %}
{%extends“base.html”%}
{%load my_tags%}
{%block title%}用户主页{%endblock%}
{%block external%}
jQuery(文档).ready(函数(){
警报('hi!');//永远无法到达!
});
{%endblock%}
{%block maincontent%}
{%endblock%}
试试看

我想在base.html ie block def for maincontent下面还有更多内容?另外,请查看firebug,它非常适合调试js和其他web内容。

解决:

如果初始模板(由其他模板扩展的模板)的jQuery ready()函数中存在错误,则其所有子模板的jQuery ready()函数都不会运行

这就是错误所在

在我的例子中,更深处出现了一个错误(找不到对.js文件的调用)。这在dev中不是一个问题,但当它进入生产环境时,在我删除错误调用之前,它不会工作。

请发布base.html和user_profile.html的代码,以显示您如何实现它们以及如何使用这些块。您是否检查了服务器中的html以确保没有错误?Jquery不应该关心js是如何组合的。您是否尝试过在firefox中使用firebug进行调试?谢谢,是否有一个web工具可以检查我的输出代码是否存在错误?
$(document).ready