我有一个Django
应用程序,使用input field
在jquery
中加载标签,如代码所示。在运行代码时,我发现应用程序无法找到bootstrap-tagsinput.css
和bootstrap-tagsinput.js
。我应该在哪里放置这些文件,以便可以检测到它们。
错误
[28/Feb/2018 12:14:23] "GET /scripts/bootstrap-tagsinput.css HTTP/1.1" 404 2191
Not Found: /scripts/bootstrap-tagsinput.js
[28/Feb/2018 12:14:23] "GET /scripts/bootstrap-tagsinput.js HTTP/1.1" 404 2188
Not Found: /scripts/bootstrap-tagsinput.js
[28/Feb/2018 12:14:23] "GET /scripts/bootstrap-tagsinput.js HTTP/1.1" 404 2188
项目目录结构
<project_name>
|--<app_name>
| |--templates
| |--index.html
|--<project_name>
|--scripts
| |--bootstrap-tagsinput.css
| |--bootstrap-tagsinput.js
|--manage.py
码
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="../scripts/bootstrap-tagsinput.css">
<title>Sample</title>
</head>
<body>
<input type="text" id="tagbar" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="../scripts/bootstrap-tagsinput.js"></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$('#tagbar').tagsinput('add', { "value": 1 ,"text": "Amsterdam" ,"continent": "Europe" });
$('#tagbar').tagsinput('add', { "value": 2 ,"text": "Washington" ,"continent": "America" });
$('#tagbar').tagsinput('add', { "value": 3 ,"text": "Sydney" ,"continent": "Australia" });
$('#tagbar').tagsinput('add', { "value": 4 ,"text": "Beijing" ,"continent": "Asia" });
$('#tagbar').tagsinput('add', { "value": 5 ,"text": "Cairo" ,"continent": "Africa" });
});
</script>
</body>
</html>
在Django中,您需要将静态文件(css,js)放在static
目录中,如https://docs.djangoproject.com/en/2.0/howto/static-files/中所述