【问题标题】:javascript 404 errorjavascript 404 错误
【发布时间】:2018-06-04 03:21:45
【问题描述】:

我正在尝试将 bower 与 django 框架一起使用。我完成了以下事情。 使用 sudo 安装凉亭。 使用 vrsion 安装的软件包:- npm:3.5.2-0ubunt, nodejs: 4.2.6~dfsg-1, 凉亭:1.8.2

这是我的以下代码:

<!DOCTYPE html>
        <html>
        <head>
            <title></title>
            <script src="bower_components/jquery/dist/jquery.min.js"></script>
            <script src="/js/foundation.js"></script>
            <script type="text/javascript">
                $(document).ready(function(){
                    alert("hello");
                });
            </script>
        </head>
        <body>
                <span class="primary label">Primary Label</span>
                <span class="secondary label">Secondary Label</span>
                <span class="success label">Success Label</span>
                <span class="alert label">Alert Label</span>
                <span class="warning label">Warning Label</span>
        </body>
        </html>

但在我的浏览器网络选项卡中收到 404 错误。请告诉我在 django 中获取工作凉亭的正确方法是什么。

【问题讨论】:

  • 只是说,用 webpack 从 bower 切换到 npm
  • 先生,我一定会试试的。但是代码不工作的原因是什么?
  • 我看不出这与 bower 有什么关系,只是您显然是在尝试从 bower_components 加载脚本。这个脚本不存在吗?您使用了哪些 bower 命令?你收到一些错误信息吗?真的不清楚你的问题是什么。
  • 我是作为包管理器的用户凉亭。我使用命令: bower install jquery --save 在 bower_components 文件夹中安装 jquery。然后我在脚本中使用用户目录来工作我的警报功能,但警报消息没有弹出,没有显示结果。我对 zurb 基础包也是如此。
  • 你好,有人看我的帖子吗?有人想弄清楚吗?

标签: javascript node.js django npm bower


【解决方案1】:

我的 jquery 包已经安装了 bower,现在正在工作。404 错误已经消失。这就是我所做的。 我的 django 项目目录,直到模板文件夹为:

DjangoProject/DjangoProject/App/templates/

我的静态文件夹目录是:

DjangoProject/DjangoProject/App/static/bower_components/jquery/dist/jquery.min.js

我将我的静态文件夹放在模板文件夹所在的位置,并为我的 js 代码放置目录,如下所示:

<!DOCTYPE html>
        <html>
        <head>
            <title></title>
            <script src="/static/bower_components/jquery/dist/jquery.min.js"></script>
            <script src="/static/bower_components/foundation-sites/js/foundation.js"></script>
            <script type="text/javascript">
                $(document).ready(function(){
                    alert("hello");
                });
            </script>
        </head>
        <body>
                <span class="primary label">Primary Label</span>
                <span class="secondary label">Secondary Label</span>
                <span class="success label">Success Label</span>
                <span class="alert label">Alert Label</span>
                <span class="warning label">Warning Label</span>
        </body>
        </html

the code has working fine for me now with 200 status code.thanks every one.

【讨论】:

    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2010-11-26
    • 2017-05-28
    相关资源
    最近更新 更多