简体   繁体   English

django-autocomplete-light 找不到 .js 脚本

[英]django-autocomplete-light can't locate .js script

I am trying to get django-autocomplete-light to work in my app.我正在尝试让 django-autocomplete-light 在我的应用程序中工作。 I think I have gotten everything setup.我想我已经完成了所有设置。

One thing that seems to be the problem is that when I include: {% include 'autocomplete_light/static.html' %}.似乎有问题的一件事是,当我包含:{% include 'autocomplete_light/static.html' %} 时。 I think my app isn't finding the necessary .js files listed below.我认为我的应用没有找到下面列出的必要 .js 文件。 When I go to the directory, I don't see the files.当我转到目录时,我看不到文件。 I thought the github download should include these files.我认为 github 下载应该包含这些文件。 Where should I be downloading these js files?我应该在哪里下载这些 js 文件? or may be directory strucuture is incorrect?或者可能是目录结构不正确?

[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 1697

Html:网址:

{% 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>

Directory structure:目录结构:

app/
    static/jquery.js
autocomplete_light/

I was having the same 404 error.我遇到了同样的 404 错误。 It was resolved after i reinstalled the django-autocomplete-light properly.在我正确地重新安装了 django-autocomplete-light 后它得到了解决。

For my case it was because i installed the package that i downloaded in zip format and extracted into a local directory:就我而言,这是因为我安装了以 zip 格式下载并解压缩到本地目录中的包:

pip install -e path_to_downloaded_package_extracted

Obviously some files were not copied or some links were not created properly.显然有些文件没有被复制或有些链接没有正确创建。

Then i started a new virtual env and gave a try to tar.gz format as follows:然后我启动了一个新的虚拟环境并尝试使用 tar.gz 格式,如下所示:

pip install --no-index -f ~/path_to_local_cache django-autocomplete-light

Than it worked.比它起作用了。 All the files were up and running.所有文件都已启动并正在运行。 Note that you must have all the required packages downloaded into the same directory for pip to deal with dependency chain.请注意,您必须将所有必需的包下载到同一目录中,以便 pip 处理依赖链。

To cite the documentation :引用文档

Configuration配置

Then, to let Django find the static files we need by adding to INSTALLED_APPS, before django.contrib.admin and grappelli if present:然后,在 django.contrib.admin 和 grappelli(如果存在)之前,通过添加到 INSTALLED_APPS来让 Django 找到我们需要的静态文件

 'dal', 'dal_select2', # 'grappelli', 'django.contrib.admin',

This is to override the jquery.init.js script provided by the admin, which sets up jQuery with noConflict, making jQuery available in django.jQuery only and not $.这是为了覆盖管理员提供的 jquery.init.js 脚本,该脚本使用 noConflict 设置 jQuery,使 jQuery 仅在 django.jQuery 中可用,而不能在 $ 中使用。

To enable more DAL functionalities we will have to add other DAL apps to INSTALLED_APPS, such as 'dal_queryset_sequence'要启用更多 DAL 功能,我们必须将其他 DAL 应用程序添加到 INSTALLED_APPS,例如“dal_queryset_sequence”

Ergo you need to make sure you configured the INSTALLED_APPS correctly.因此,您需要确保正确配置了 INSTALLED_APPS。

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

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