我正在尝试让django-autocomplete-light在我的应用程序中工作。我想我已经把一切都准备好了。
有一件事似乎是问题所在:{% include 'autocomplete_light/static.html‘%}。我想我的应用程序找不到下面列出的必要的.js文件。当我转到目录时,我看不到文件。我认为github下载应该包含这些文件。我应该在哪里下载这些js文件?或者可能是目录结构不正确?
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/autocomplete.js HTTP/1.1" 404 1715
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/django_admin.js HTTP/1.1" 404 1715
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/text_widget.js HTTP/1.1" 404 1712
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/widget.js HTTP/1.1" 404 1697
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/style.css HTTP/1.1" 404 1697
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/addanother.js HTTP/1.1" 404 1709
[21/Nov/2015 10:59:30] "GET /static/autocomplete_light/remote.js HTTP/1.1" 404 1697Html:
{% load staticfiles %}
<script type="text/javascript" src="{% static 'jquery.js' %}">
$(document).ready(function() {
$('#add_user_accounts').InstitutionAutocomplete({
url: '{% url 'add_user_accounts' %}',
choiceSelector: 'a',
}).input.bind('selectChoice', function(e, choice, autocomplete) {
document.location.href = choice.attr('href');
});
});
</script>
{% include 'autocomplete_light/static.html' %}
<input type="text" name="q" id="add_users_accounts" placeholder="Find your institution" style="width: 270px; font-size: 12px;" />
<style type="text/css">
/* cancel out django default for now, or choices are white on white */
#header a.choice:link, #header a.choice:visited {
color: black;
}
</style>目录结构:
app/
static/jquery.js
autocomplete_light/发布于 2016-01-04 17:17:16
我也遇到了同样的404错误。在我正确地重新安装了django-autocomplete-light之后,这个问题就解决了。
对于我的例子,这是因为我安装了以zip格式下载的包,并将其解压缩到本地目录中:
pip install -e path_to_downloaded_package_extracted显然,有些文件没有被复制,或者有些链接没有正确创建。
然后我启动了一个新的虚拟环境,并尝试了tar.gz格式,如下所示:
pip install --no-index -f ~/path_to_local_cache django-autocomplete-light比它的效果更好。所有文件都已启动并运行。请注意,您必须将所有必需的包下载到相同的目录中,以便pip处理依赖链。
发布于 2020-12-10 17:05:17
配置
然后,在django.contrib.admin和grappelli之前添加,让Django找到我们需要的静态文件,如果有的话:
'dal','dal_select2',# 'grappelli',‘django.contri.admin’,
这将覆盖管理员提供的jquery.init.js脚本,该脚本使用noConflict设置jQuery,使jQuery仅在django.jQuery中可用,而在$中不可用。
要启用更多DAL功能,我们必须将其他DAL应用程序添加到INSTALLED_APPS中,如‘dal_queryset_sequence’
因此,您需要确保正确配置了INSTALLED_APPS。
https://stackoverflow.com/questions/33847665
复制相似问题