I am uisng python,To display data from json file to a page,i am getting the below errors
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 file
$("#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 file is
{
"p1":{
"item1":"apple",
"item2":"orange",
"item3":"banana",
},
"p2":{
"item1":"water",
"item2":"milk",
"item3":"alcohol",
}
}
template is
<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 file is in my project folder and path also setted.
2).I am not doing any query in my views.py,as i am new to this i am confused with this.So any codings need to perform in the views.py for fetching the data from json.
3).Not able to sort out the above errors,please provide me the possible reason so that i can run this function.
Thanks
The only way to fix this is to make sure that the CSS and JS files are properly linked within the HTML. Check whether the folder, file and directory name of these files are spelt correctly. Another way to fix this is by using an absolute URL instead of a relative URL.
The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource. Links that lead to a 404 page are often called broken or dead links and can be subject to link rot.
you need to set STATICFILES_DIRS
in settings.py
but make sure your file tree is like below
RootDir
+--myproject
| +--static
| | +--script
| | |--myscript.js
| | |--jquery-1.9.1.min.js
| |--settings.py
+--myapp
|--manage.py
in settings.py
add or replace
STATIC_URL = '/static/'
with
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
STATIC_URL = '/static/'
another fix:
replace comma ,
in <script src="script/jquery-1.9.1,min.js"
and
add double quote "
, replace "<li>+value.item1+"</li>"
with "<li>"+value.item1+"</li>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With