简体   繁体   English

Django关于AJAX请求的相对路径的最佳实践

[英]Django best practice on relative path from an AJAX request

I am currently failing at trying to read a CSV file stored in my django static repository from an AJAX request. 我目前无法尝试从AJAX请求读取存储在django静态存储库中的CSV文件。

Failed to load resource: http://127.0.0.1:8000/static/users/feedbacks/data.csv
the server responded with a status of 404 (Not Found)

Is there a best practice for this to work properly as well in production? 是否有最佳实践,使其在生产中也能正常工作?

here is the js : 这是js

if (replayCSV){
    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "/static/users/feedbacks/data.csv",
            dataType: "csv",
            success: function(data) {readData(data);}
         });
        console.log(dataToRead);
    });
}

And my django project structure looks like: 我的django项目结构如下:

main_repository
-...
-project_folder
--app_folder
---static
----js
-----therequest.js
static_repository
-static
--users
---feedbacks
----data.csv

RESOLVED I am leaving the question as is and the solution below if someone run into similar problem. 议决我留下了一个问题,就是以下,如果有人遇到类似问题的解决方案。 Simply enough, the dataType was wrong. 简而言之,dataType是错误的。

change dataType: "csv" with dataType: "text" 使用dataType: "text"更改dataType: "csv" dataType: "text"

This will allow to get the csv file properly according to the given path 这将允许根据给定的路径正确获取csv文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM