【问题标题】:Django static files didn't workDjango 静态文件不起作用
【发布时间】:2016-08-20 22:13:22
【问题描述】:

我正在使用 django,但我的 html 文件有问题,一些文件在我“加载静态文件”时有效,而其他类似的文件无效,我不明白为什么!我错过了什么吗???

有我的两个文件

<!DOCTYPE html>
{% load staticfiles %}
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
    <link href="{% static "remote/css/bootstrap.min.css" %}" rel="stylesheet">
    <link href="{% static "remote/font-awesome/css/font-awesome.css" %}" rel="stylesheet">
    <!-- Toastr style -->
    <link href="{% static "remote/css/plugins/toastr/toastr.min.csss" %}" rel="stylesheet">
    <!-- Gritter -->
    <link href="{% static "remote/js/plugins/gritter/jquery.gritter.css" %}" rel="stylesheet">
    <link href="{% static "remote/css/animate.css" %}" rel="stylesheet">
    <link href="{% static "remote/css/style.css" %}" rel="stylesheet">
    <style>
        body.DTTT_Print {
            background: #fff;

        }

        .DTTT_Print #page-wrapper {
            margin: 0;
            background: #fff;
        }

        button.DTTT_button, div.DTTT_button, a.DTTT_button {
            border: 1px solid #e7eaec;
            background: #fff;
            color: #676a6c;
            box-shadow: none;
            padding: 6px 8px;
        }

        button.DTTT_button:hover, div.DTTT_button:hover, a.DTTT_button:hover {
            border: 1px solid #d2d2d2;
            background: #fff;
            color: #676a6c;
            box-shadow: none;
            padding: 6px 8px;
        }

        .dataTables_filter label {
            margin-right: 5px;

        }
    </style>
</head>
<body class="pace-done mini-navbar">
<div id="wrapper">
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">

                <li class="nav-header">
                    <div class="dropdown profile-element"> <span>

                             </span>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear"> <span class="block m-t-xs">
                                <strong class="font-bold">
   coucou


                       </strong>
                             </span><span class="text-muted text-xs block"> Profil <strong
                                    class="caret"></strong></span></span> </a>
                        <ul class="dropdown-menu animated fadeInRight m-t-xs">
                            <li><a href="#">Profile</a></li>
                            <li><a href="#">Messagerie</a></li>
                            <li class="divider"></li>
                            <li><a href="login.html">Se déconnecter</a></li>
                        </ul>
                    </div>
                    <div class="logo-element">
                        UC2
                    </div>
                </li>
                <li class="active">
                    <a href="Index1.php"><i class="fa fa-home"></i> <span class="nav-label">ACCUEIL</span> <span
                            class="fa arrow"></span></a>

                </li>
                <li>
                    <a href="Emploie.php"> <i class="fa fa-dashboard"></i> <span
                            class="nav-label">Emploie du temps</span> </a>
                </li>

                <li>
                    <a href="Messagerie.php"> <i class="fa fa-envelope-o"></i> <span class="nav-label">Messagerie</span>
                    </a>
                </li>
                <li>
                    <a href="Module_charge.php"> <i class="fa fa-credit-card"></i> <span class="nav-label">Module en charge</span>
                    </a>
                </li>
                <li>
                    <a href="Evaluation.php"> <i class="fa fa-file-text-o"></i> <span class="nav-label">Mode d'évaluation</span>
                    </a>
                </li>


                <li class="special_link">
                    <a href="Profile.php"><i class="fa fa-user"></i> <span class="nav-label">Profil</span></a>
                </li>
                </il>
            </ul>
        </div>
    </nav>

    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i>
                    </a>
                    <form role="search" class="navbar-form-custom" action="#">
                        <div class="form-group">

                        </div>
                    </form>
                </div>


                <ul class="nav navbar-top-links navbar-right ">
                    <li>
                    <span>
               Bienvenue,



                    </span>
                    </li>


                    <li>
                        <a href="login.html">
                            <i class="fa fa-sign-out"></i> Déconnecter
                        </a>
                    </li>
                    <li>
                        <a class="right-sidebar-toggle">
                            <i class="fa fa-tasks"></i>
                        </a>
                    </li>
                </ul>

            </nav>
        </div>

        <div class="row  border-bottom white-bg dashboard-header">
            <div class="row">
                <div class="col-lg-6">
                    <div class="widget style1">
                        <div class="row">
                            <div class="col-xs-4 text-center Animated tada">
                                <!--<img src="Logo.png" width="130" height="130" alt="icone">   this is a com -->

                            </div>
                            <div class="col-xs-8 text-center">
                                <span>
                                        <p> hey ! salut toi :)) , tu es à present sur ton espace personnel où plusieurs service sont
                                        à ta disposition </p>



                                </span>
                                <h2 class="font-bold"></h2>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 animated bounceInLeft">
                    <div class="widget style1 navy-bg">
                        <div class="row">
                            <div class="col-xs-4">
                                <i class="fa fa-cloud fa-5x"></i>
                            </div>
                            <div class="col-xs-8 text-right">
                                <span> Messagerie </span>
                                <h2 class="font-bold">3</h2>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 animated bounceInLeft">
                    <div class="widget style1 navy-bg">
                        <div class="row">
                            <div class="col-xs-4">
                                <i class="fa fa-envelope-o fa-5x"></i>
                            </div>
                            <div class="col-xs-8 text-right">
                                <span> Telecharger CV </span>
                                <h2 class="font-bold">3</h2>
                            </div>
                        </div>
                    </div>
                </div>


            </div>


            <div class="row">
                <a href="Profile.php">
                    <div class="col-lg-4">
                        <div class="widget lazur-bg p-lg text-center ">
                            <div class="m-b-md">
                                <h2 class="font-bold no-margins">
                                    <?php
                 $Nom =$_SESSION['Nom'];
                      $Prenom=$_SESSION['Prenom'];

             echo ''.$Nom.' '.$Prenom ;


                       ?>
                                </h2>
                                <small>Profil</small>
                            </div>

                            <i class="fa fa-User fa-5x"></i>

                            <br>
                            <br>
                            <br>
                        </div>
                        <div class="widget-text-box">
                            <h4 class="media-heading"> <?php
                 $Nom =$_SESSION['Nom'];
                      $Prenom=$_SESSION['Prenom'];

             echo ''.$Nom.' '.$Prenom ;


                       ?>   </h4>
                            <p>

                                <?php
                 $Nom =$_SESSION['Nom'];
                      $Prenom=$_SESSION['Prenom'];
                      $Univ= $_SESSION['Univ'];
                      $Departement = $_SESSION['Depart'];
                      $Faculte = $_SESSION['Faculte'];
             echo  'Enseignant à L'.$Univ.' , Faculté des '.$Faculte.' , département '.$Departement  ;


                       ?>

                            </p>

                            <div class="text-right">
                                <a class="btn btn-xs btn-primary"><i class="fa fa-thumbs-up"></i> Profile</a>
                            </div>
                        </div>
                    </div>
                </a>
                <a href="Emploie.php">
                    <div class="col-lg-2 animated rubberBand">
                        <div class="widget navy-bg p-lg text-center">
                            <div class="m-b-md">
                                <i class="fa fa-dashboard fa-4x"></i>
                                <h1 class="m-xs"></h1>
                                <h3 class="font-bold no-margins">
                                    CV
                                </h3>
                                <small>Creer ici votre CV !</small>
                            </div>

                        </div>
                        <div class="widget navy-bg p-lg text-center">
                            <div class="m-b-md">
                                <i class="fa fa-dashboard fa-4x"></i>
                                <h1 class="m-xs"></h1>
                                <h3 class="font-bold no-margins">
                                    Mettre à jour CV
                                </h3>
                                <small></small>
                            </div>

                        </div>
                        <div class="widget  p-lg text-center">
                        </div>
                    </div>
                </a>

                <div class="col-lg-6 animated rubberBand">
                    <a href="Messagerie.php">
                        <div class="widget yellow-bg p-lg text-center ">
                            <div class="m-b-md">
                                <i class="fa fa-file-text-o fa-4x"></i>
                                <h1 class="m-xs"></h1>
                                <h3 class="font-bold no-margins">
                                    Stages
                                </h3>
                                <small>rechercher des stages par mot clés</small>
                            </div>
                        </div>
                    </a>


                    <a href="Module_charge.php">
                        <div class="widget red-bg p-lg text-center ">
                            <div class="m-b-md">
                                <i class="fa fa-credit-card fa-4x"></i>
                                <h1 class="m-xs"></h1>
                                <h3 class="font-bold no-margins">
                                    Rechercher une formation
                                </h3>
                            </div>
                        </div>
                    </a>
            </div>
        </div>
    </div>
    <div w3-include-html="remote/Footer.html"></div>
</body>
</html>

和:

           <div class="footer">

                    <div>
                        <strong>Copyright</strong>
                    </div>
                </div>
            </div>
        </div>

        </div>


    </div>

    <!-- Mainly scripts -->
    <script src="{% static "container/js/jquery-2.1.1.js" %}"></script>
    <script src="{% static "container/js/bootstrap.min.js" %}"></script>
    <script src="{% static "container/js/plugins/metisMenu/jquery.metisMenu.js" %}"></script>
    <script src="{% static "container/js/plugins/slimscroll/jquery.slimscroll.min.js" %}"></script>

    <!-- Flot -->
    <script src="{% static "container/js/plugins/flot/jquery.flot.js" %}"></script>
    <script src="{% static "container/js/plugins/flot/jquery.flot.tooltip.min.js" %}"></script>
    <script src="{% static "container/js/plugins/flot/jquery.flot.spline.js" %}"></script>
    <script src="{% static "container/js/plugins/flot/jquery.flot.resize.js" %}"></script>
    <script src="{% static "container/js/plugins/flot/jquery.flot.pie.js" %}"></script>

    <!-- Peity -->
    <script src="{% static "container/js/plugins/peity/jquery.peity.min.js" %}"></script>
    <script src="{% static "container/js/demo/peity-demo.js" %}"></script>

    <!-- Custom and plugin javascript -->
    <script src="{% static "container/js/inspinia.js" %}"></script>
    <script src="{% static "container/js/plugins/pace/pace.min.js" %}"></script>

    <!-- jQuery UI -->
    <script src="{% static "container/js/plugins/jquery-ui/jquery-ui.min.js" %}"></script>

    <!-- GITTER -->
    <script src="{% static "container/js/plugins/gritter/jquery.gritter.min.js" %}"></script>

    <!-- Sparkline -->
    <script src="{% static "container/js/plugins/sparkline/jquery.sparkline.min.js" %}"></script>

    <!-- Sparkline demo data  -->
    <script src="{% static "container/js/demo/sparkline-demo.js" %}"></script>

    <!-- ChartJS-->
    <script src="{% static "container/js/plugins/chartJs/Chart.min.js" %}"></script>

    <!-- Toastr -->
    <script src="{% static "container/js/plugins/toastr/toastr.min.js" %}"></script>


    <script src="{% static "container/js/plugins/validate/jquery.validate.min.js" %}"></script>



  <!-- Data Tables -->
    <script src="{% static "container/js/plugins/dataTables/jquery.dataTables.js" %}"></script>
    <script src="{% static "container/js/plugins/dataTables/dataTables.bootstrap.js" %}"></script>
    <script src="{% static "container/js/plugins/dataTables/dataTables.responsive.js" %}"></script>
    <script src="{% static "container/js/plugins/dataTables/dataTables.tableTools.min.js" %}"></script>

   <!-- Rickshaw -->
    <script src="{% static "container/js/plugins/rickshaw/vendor/d3.v3.js" %}"></script>
    <script src="{% static "container/js/plugins/rickshaw/rickshaw.min.js" %}"></script>

    <!-- Page-Level Scripts -->


    <script>
         $(document).ready(function(){

             $("#form").validate({
                 rules: {
                     password: {
                         required: true,
                         minlength: 3
                     },
                     url: {
                         required: true,
                         url: true
                     },
                     number: {
                         required: true,
                         number: true
                     },
                     min: {
                         required: true,
                         minlength: 6
                     },
                     max: {
                         required: true,
                         maxlength: 4
                     }
                 }
             });
        });
    </script>

    <script>
        $(document).ready(function() {
            setTimeout(function() {
                toastr.options = {
                    closeButton: true,
                    progressBar: true,
                    showMethod: 'slideDown',
                    timeOut: 4000
                };
                toastr.success('Bienvenue dans votre session', 'Mme/Mr,');

            }, 1300);


            var data1 = [
                [0,4],[1,8],[2,5],[3,10],[4,4],[5,16],[6,5],[7,11],[8,6],[9,11],[10,30],[11,10],[12,13],[13,4],[14,3],[15,3],[16,6]
            ];
            var data2 = [
                [0,1],[1,0],[2,2],[3,0],[4,1],[5,3],[6,1],[7,5],[8,2],[9,3],[10,2],[11,1],[12,0],[13,2],[14,8],[15,0],[16,0]
            ];
            $("#flot-dashboard-chart").length && $.plot($("#flot-dashboard-chart"), [
                data1, data2
            ],
                    {
                        series: {
                            lines: {
                                show: false,
                                fill: true
                            },
                            splines: {
                                show: true,
                                tension: 0.4,
                                lineWidth: 1,
                                fill: 0.4
                            },
                            points: {
                                radius: 0,
                                show: true
                            },
                            shadowSize: 2
                        },
                        grid: {
                            hoverable: true,
                            clickable: true,
                            tickColor: "#d5d5d5",
                            borderWidth: 1,
                            color: '#d5d5d5'
                        },
                        colors: ["#1ab394", "#464f88"],
                        xaxis:{
                        },
                        yaxis: {
                            ticks: 4
                        },
                        tooltip: false
                    }
            );

            var doughnutData = [
                {
                    value: 300,
                    color: "#a3e1d4",
                    highlight: "#1ab394",
                    label: "App"
                },
                {
                    value: 50,
                    color: "#dedede",
                    highlight: "#1ab394",
                    label: "Software"
                },
                {
                    value: 100,
                    color: "#b5b8cf",
                    highlight: "#1ab394",
                    label: "Laptop"
                }
            ];

            var doughnutOptions = {
                segmentShowStroke: true,
                segmentStrokeColor: "#fff",
                segmentStrokeWidth: 2,
                percentageInnerCutout: 45, // This is 0 for Pie charts
                animationSteps: 100,
                animationEasing: "easeOutBounce",
                animateRotate: true,
                animateScale: false,
            };

            var ctx = document.getElementById("doughnutChart").getContext("2d");
            var DoughnutChart = new Chart(ctx).Doughnut(doughnutData, doughnutOptions);

            var polarData = [
                {
                    value: 300,
                    color: "#a3e1d4",
                    highlight: "#1ab394",
                    label: "App"
                },
                {
                    value: 140,
                    color: "#dedede",
                    highlight: "#1ab394",
                    label: "Software"
                },
                {
                    value: 200,
                    color: "#b5b8cf",
                    highlight: "#1ab394",
                    label: "Laptop"
                }
            ];

            var polarOptions = {
                scaleShowLabelBackdrop: true,
                scaleBackdropColor: "rgba(255,255,255,0.75)",
                scaleBeginAtZero: true,
                scaleBackdropPaddingY: 1,
                scaleBackdropPaddingX: 1,
                scaleShowLine: true,
                segmentShowStroke: true,
                segmentStrokeColor: "#fff",
                segmentStrokeWidth: 2,
                animationSteps: 100,
                animationEasing: "easeOutBounce",
                animateRotate: true,
                animateScale: false,
            };
            var ctx = document.getElementById("polarChart").getContext("2d");
            var Polarchart = new Chart(ctx).PolarArea(polarData, polarOptions);

        });
    </script>
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','../../www.google-analytics.com/analytics.js','ga');

        ga('create', 'UA-4625583-2', 'webapplayers.com');
        ga('send', 'pageview');

    </script>
   <script>
        $(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "tableTools": {
                    "sSwfPath": "js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });

            /* Init DataTables */
            var oTable = $('#editable').dataTable();

            /* Apply the jEditable handlers to the table */
            oTable.$('td').editable( 'http://webapplayers.com/example_ajax.php', {
                "callback": function( sValue, y ) {
                    var aPos = oTable.fnGetPosition( this );
                    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
                },
                "submitdata": function ( value, settings ) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition( this )[2]
                    };
                },

                "width": "90%",
                "height": "100%"
            } );


        });

        function fnClickAddRow() {
            $('#editable').dataTable().fnAddData( [
                "Custom row",
                "New row",
                "New row",
                "New row",
                "New row" ] );

        }
    </script>
    <script>


        $(document).ready(function() {
            $('.animation_select').click( function(){
                $('#animation_box').removeAttr('class').attr('class', '');
                var animation = $(this).attr("data-animation");
                $('#animation_box').addClass('animated');
                $('#animation_box').addClass(animation);
                return false;
            });

            var graph2 = new Rickshaw.Graph( {
                element: document.querySelector("#rickshaw_multi"),
                renderer: 'area',
                stroke: true,
                series: [ {
                    data: [ { x: 0, y: 2 }, { x: 1, y: 5 }, { x: 2, y: 8 }, { x: 3, y: 4 }, { x: 4, y: 8 } ],
                    color: '#1ab394',
                    stroke: '#17997f'
                }, {
                    data: [ { x: 0, y: 13 }, { x: 1, y: 15 }, { x: 2, y: 17 }, { x: 3, y: 12 }, { x: 4, y: 10 } ],
                    color: '#eeeeee',
                    stroke: '#d7d7d7'
                } ]
            } );
            graph2.renderer.unstack = true;
            graph2.render();
        });
    </script>
</body>

<!-- Mirrored from webapplayers.com/inspinia_admin-v2.1/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 28 May 2015 11:05:15 GMT -->
</html>

我的 css 和 js 在静态/远程目录中

【问题讨论】:

  • 我看到我忘记在第二个文件中重命名远程容器,顺便说一下它没有改变任何它不起作用的东西!
  • 请检查 settings.py 文件中为 STATICFILES_DIRS 提供的路径。另外,第二个文件中的“容器”是什么意思,因为 css 和 js 文件都在 /static/remote 目录中?
  • 是的,在你的 settings.py 中检查 STATICFILES_DIRS 和 STATIC_ROOT

标签: django html django-templates


【解决方案1】:

静态目录所在的包必须包含在 INSTALLED_APPS 中,否则不起作用。

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 2015-11-09
    • 2015-07-09
    • 1970-01-01
    • 2015-03-30
    • 2012-01-14
    • 2016-02-11
    • 2020-09-12
    相关资源
    最近更新 更多