我正在用Python重写一个现有的基于Java的网站。经过大量的研究,我决定使用Django,并且到目前为止,这个项目已经取得了一些良好的进展。在
然而,我却无法使用之前网站上的一些代码。我对使用scripts.js
文件特别感兴趣,它似乎具有网站所需的所有JavaScript功能,但不确定如何将其与我的Django项目集成。在
我能简单地把这个文件放在我的static
文件夹中并引用各个应用程序的函数吗?如果是,我该如何调用函数?鉴于文件现在必须使用基于Python的网站,而不是基于Java的网站,我是否需要对该文件进行任何更改?在
我还附加了一个scripts.js
文件的片段,让您了解函数的样子。在
function gatewayGetAllInformation(){
if(controlsLocked) {
return;
}
lockControls();
getFiles();
gatewayGetShifts();
getCatNews();
getDepNews();
getSales();
getPermanentSales();
adminGetUsers();
unlockControls();
};
function gatewayGetShifts(){
var url = root +"/AjaxResponder?action=getShifts";
var xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystate = function() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var shiftsHTML =gatewayParseShifts(xmlHttp.responseXML);
setInnerHTML("upcomingShiftsList",shiftsHTML); // added semicolon
}
else {
setInnerHTML("upcomingShiftsList", "Error Getting Users");
}
}
};
xmlHttp.open("POST", url, true);
xmlHttp.send(null);
谢谢!在
是的,您只需要将您的
script.js
放在/static/
文件夹中。在在你的模板中你称之为
^{pr2}$仅此而已,您可以使用}函数。在
gatewayGetAllInformation
和{但请记住更新
script.js
中的常量值您可以将javascript文件放在静态文件夹中。在
path/to/your/file.js
是相对于static
文件夹的路径。在您应该使用django-compressor缩小生产环境中的文件。在
只要在Django应用程序中定义的路由与Java应用程序中为AJAX调用定义的路由相同,就不必更改javascript文件的内容。在
相关问题 更多 >
编程相关推荐