Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.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 Javascript_Django - Fatal编程技术网

关于Django Javascript

关于Django Javascript,django,Django,我不知道如何为Django编写javascript? 请帮帮我 index.html {% extends "base.html" %} <html> <head> </head> <body> <script type="text/javascript"> $(document).ready(function() { $("#sampleTable").tablesorter();

我不知道如何为Django编写javascript? 请帮帮我

index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>
下面的javascript代码是否正确

index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>
此代码以HTML格式编写: base.html: {%load staticfiles%}

index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>
index.html
{%extends“base.html”%}
$(文档).ready(函数()
{
$(“#sampleTable”).tablesorter();
);
名称
公司
{%if memo.count>0%}
{备忘录%中的用户为%1}

默认情况下,Django与Javascript无关。它只是呈现模板并返回HTML。您可以为Django编写Javascript,就像在其他任何地方编写一样

index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>
不管那个特定的代码是否正确,运行它。如果它运行了,那么它是正确的,如果不正确,您就有一些错误。但它们很可能与Django无关

index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>

顺便说一句,您的代码不完整。您尚未关闭模板中
if
块。此外,如果您正在扩展
base.html
,则您的html应该位于
base.html
中定义的块内。请在编写代码之前阅读。

编写javascript“for django”与为任何其他网站编写javascript没有任何区别。请像在任何html文件中使用一样轻松地使用javascript。但是,在上载的html代码中有一些语法错误,{%if%}和{%for%}块请参考django模板文档。非常感谢!我应该使用{%if%}和{%for%}
index.html

{% extends "base.html" %}
<html>
<head>
</head>
<body>
<script type="text/javascript">
   $(document).ready(function()
       {
           $("#sampleTable").tablesorter();

   );
</script>

<div class="import">

    <table id="sampleTable" class="tablesorter">
        <thead>
            <tr>
                <th class="{sorter:'metadata'}" style="width:100px">name</th>
                <th class="{sorter:'metadata'}"  style="width:260px">company</th>

            </tr>
        </thead>
    </table>


{% if memo.count > 0 %}
{% for user in memo %}
<div><h3>
    <table id="sampleTable1" class="tablesorter">
        <tbody>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.user_name }}</a></td>
        <td style=" border-bottom:1px solid #0099cc; text-align:center;"><a href="/memo/get/{{ user.id }}/">{{ user.company }}</a></td>
        </tbody>
    </table>
</div>
</body>
</html>