关键词:
【中文标题】加载资源失败:服务器响应状态为 404(未找到)【英文标题】:Failed to load resource: the server responded with a status of 404 (NOT FOUND) 【发布时间】:2013-03-30 03:23:16 【问题描述】:我是 uisng python,要将数据从 json 文件显示到页面,我收到以下错误
Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://localhost:8000/static/script/jquery-1.9.1.min.js
Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://localhost:8000/static/script/myscript.js
myscript.js 文件
$("#button").click(function()
$.getJSON("item.json",function(obj)
$.each(obj,function(key,value)
$("ul").append("<li>+value.item1+"</li>");
$("ul").append("<li>+value.item2+"</li>");
$("ul").append("<li>+value.item3+"</li>");
);
);
);
.json 文件是
"p1":
"item1":"apple",
"item2":"orange",
"item3":"banana",
,
"p2":
"item1":"water",
"item2":"milk",
"item3":"alcohol",
模板是
<html>
<head>
<body>
<ul></ul>
<button></button>
<script src="script/jquery-1.9.1,min.js" type="text/javascript"></script>
<script src="script/myscript.js" type="text/javascript"></script>
</body>
</head>
</html>
1).js 文件在我的项目文件夹中,路径也设置好了。
2)。我没有在我的views.py 中做任何查询,因为我是新手,我对此感到困惑。所以任何编码都需要在views.py 中执行以从json 中获取数据。
3).无法解决上述错误,请提供可能的原因,以便我可以运行此功能。
谢谢
【问题讨论】:
如果这正是你的代码,你在这里有一个错误:` $("ul").append("+value.item1+"");` , missing " 之后(这可能不是你的问题的解决方案,但至少你的 js 不会崩溃) 我建议你直接在浏览器中打开那些<script src=
链接,看看会发生什么。我也期望 404,这意味着 src
路径是错误的。
@Daniel 我纠正了这一点,即使我遇到了同样的错误
@akoskm 我在浏览器中检查脚本 src 链接时遇到同样的错误,所以如何设置路径,我提到了与脚本 src 相同的文件路径,有什么不同的地方需要提一下。请告诉我
@MonkL 不,当您将路径粘贴到浏览器或通过脚本标签检索它时,路径应该等效。此行为意味着src
下的路径无效,并且您的脚本被放置在其他位置。
【参考方案1】:
您需要在settings.py
中设置STATICFILES_DIRS
,但请确保您的文件树如下所示
RootDir
+--myproject
| +--static
| | +--script
| | |--myscript.js
| | |--jquery-1.9.1.min.js
| |--settings.py
+--myapp
|--manage.py
在settings.py
中添加或替换
STATIC_URL = '/static/'
与
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
STATIC_URL = '/static/'
另一个修复:
在<script src="script/jquery-1.9.1,min.js"
中替换逗号,
和
添加双引号"
,将"<li>+value.item1+"</li>"
替换为"<li>"+value.item1+"</li>"
【讨论】:
【参考方案2】:你必须在你的 django 设置文件中设置你的 STATIC_URL
和 STATIC_ROOT
,在你的 js src 路径前加上 STATIC_URL
,并告诉 django 在使用开发服务器时提供静态内容(和/或配置你的前端服务器为其提供服务)。全部记录在这里:https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/
注意:在 1.3 版之前,它是 MEDIA_URL 和 MEDIA_ROOT,参见相关文档。
【讨论】:
【参考方案3】:用于开发服务器
-
在 django 根目录下创建一个静态文件夹
将此添加到 settings.py 中的 STATIC_DIRS
('assets','静态文件夹路径')
将资源放在您之前创建的静态文件夹中的相应文件夹中
然后运行 python manage.py collectstatic。这将在 django 根目录中创建一个管理员和一个资产文件夹,其中包含您放置的资产
在模板中,在顶部添加 % load static %
对于链接,请使用 % static 'assets/path_to_resources_as_added_in_the_static_folder' %
这对我有用
【讨论】:
Apache Cordova:“加载资源失败:服务器响应状态为 404(未找到)”
】ApacheCordova:“加载资源失败:服务器响应状态为404(未找到)”【英文标题】:ApacheCordova:"Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)"【发布时间】:2016-01-0408:48:27【问题描述】:我收到错误消息:“加载资源... 查看详情
加载资源失败:服务器响应状态为 404(未找到)
】加载资源失败:服务器响应状态为404(未找到)【英文标题】:Failedtoloadresource:theserverrespondedwithastatus404(notfound)【发布时间】:2015-12-0117:06:28【问题描述】:我在javascript和ajax上遵循lynda教程,并在主题“使用同步XHR请求”主... 查看详情
加载资源失败:服务器响应状态为 404(未找到)
】加载资源失败:服务器响应状态为404(未找到)【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)【发布时间】:2014-07-1520:37:19【问题描述】:我在Eclipse中使用WorklightStudio。我创建了一个新工作区并创建了一个... 查看详情
加载资源失败:服务器响应状态为 404(未找到)显示在控制台上
】加载资源失败:服务器响应状态为404(未找到)显示在控制台上【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)displayedonconsole【发布时间】:2021-10-2319:00:43【问题描述】:Image我的文件结构是index.html、script.js... 查看详情
Angular 5 - 加载资源失败:服务器响应状态为 404(未找到)
】Angular5-加载资源失败:服务器响应状态为404(未找到)【英文标题】:Angular5-Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)【发布时间】:2018-09-0703:44:17【问题描述】:我正在尝试从node_modules中的包中获取svg图像,我从我... 查看详情
加载资源失败:服务器使用 laravel 8 / ajax 响应状态为 404(未找到)
】加载资源失败:服务器使用laravel8/ajax响应状态为404(未找到)【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)usinglaravel8/ajax【发布时间】:2021-09-1018:09:10【问题描述】:我正在尝试在HTMLbloc中显示图像,所以... 查看详情
加载资源失败:http://website.azurewebsites.net/signalr/hubs 服务器响应状态为 404(未找到)
】加载资源失败:http://website.azurewebsites.net/signalr/hubs服务器响应状态为404(未找到)【英文标题】:Failedtoloadresource:thehttp://website.azurewebsites.net/signalr/hubsserverrespondedwithastatusof404(NotFound)【发布时间】:2017-01-0421:19:02【问题描述】... 查看详情
在本地解析服务器上运行的解析仪表板错误出现:加载资源失败:服务器响应状态为 404(未找到)
】在本地解析服务器上运行的解析仪表板错误出现:加载资源失败:服务器响应状态为404(未找到)【英文标题】:parse-dashboardrunningonlocalparse-servererrorsoutinwith:Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)【发布时间】:2021... 查看详情
为啥 Wordpress 无法加载资源?它表示服务器响应状态为 404(未找到)
】为啥Wordpress无法加载资源?它表示服务器响应状态为404(未找到)【英文标题】:whyWordpressfailedtoloadtheresource?Itsaidthattheserverrespondedwithastatusof404(notFound)为什么Wordpress无法加载资源?它表示服务器响应状态为404(未找到)【发布... 查看详情
“加载资源失败:服务器响应状态为 404”express docker
】“加载资源失败:服务器响应状态为404”expressdocker【英文标题】:"Failedtoloadresource:theserverrespondedwithastatusof404"expressdocker【发布时间】:2019-01-2720:38:51【问题描述】:我在浏览器中收到错误消息“加载资源失败:服务器... 查看详情
csharp在控制台navegator出现时:“无法加载资源:服务器响应状态为404(未找到)”是因为iis不k(代码片段)
加载资源失败:服务器响应状态为 404 () font-awesome [重复]
】加载资源失败:服务器响应状态为404()font-awesome[重复]【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404()font-awesome[duplicate]【发布时间】:2021-11-0923:32:12【问题描述】:我正在使用jsf和adminlte主题。我在使用图标时遇到... 查看详情
加载资源失败:服务器使用 Angular 响应状态为 404 (),使用 GitHub Pages 部署
】加载资源失败:服务器使用Angular响应状态为404(),使用GitHubPages部署【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404()usingAngular,deployingwithGitHubPages【发布时间】:2021-07-3020:49:51【问题描述】:我正在尝试使用Angular和Gi... 查看详情
加载资源失败:服务器响应状态为 404 () Spring boot with JWT
】加载资源失败:服务器响应状态为404()SpringbootwithJWT【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404()SpringbootwithJWT【发布时间】:2021-10-2118:35:55【问题描述】:您好,我正在使用Jwt安全性创建SpringBoot项目来为用户生... 查看详情
加载资源失败:服务器响应状态为 404 (Not Found) angular js + ionic
】加载资源失败:服务器响应状态为404(NotFound)angularjs+ionic【英文标题】:Failedtoloadresource:theserverrespondedwithastatusof404(NotFound)angularjs+ionic【发布时间】:2014-09-2523:27:12【问题描述】:这是我在GoogleDevtTools中遇到的错误。有谁知道这... 查看详情
获取 Javascript 服务加载资源失败:服务器响应状态为 401(未授权)
】获取Javascript服务加载资源失败:服务器响应状态为401(未授权)【英文标题】:fetchJavascriptserviceFailedtoloadresource:theserverrespondedwithastatusof401(Unauthorized)【发布时间】:2021-01-2900:01:18【问题描述】:我尝试使用javascript(特别是获... 查看详情
在 CPanel 上部署 Node.js React 应用程序 - “加载资源失败:服务器响应状态为 404 ()”
】在CPanel上部署Node.jsReact应用程序-“加载资源失败:服务器响应状态为404()”【英文标题】:DeployingaNode.jsReactApp,onCPanel-\'Failedtoloadresource:theserverrespondedwithastatusof404()\'【发布时间】:2019-08-1121:46:37【问题描述】:我将构建文件夹... 查看详情
散景内联嵌入,“加载资源失败”
...试嵌入散景图内联时,出现以下错误:“加载资源失败:服务器响应状态为404(未找到)”,引用此链接-https:/ 查看详情