简体   繁体   中英

django-autocomplete-light can't locate .js script

I am trying to get django-autocomplete-light to work in my app. 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' %}. I think my app isn't finding the necessary .js files listed below. When I go to the directory, I don't see the files. I thought the github download should include these files. Where should I be downloading these js files? 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. It was resolved after i reinstalled the django-autocomplete-light properly.

For my case it was because i installed the package that i downloaded in zip format and extracted into a local directory:

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:

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.

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:

 '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 $.

To enable more DAL functionalities we will have to add other DAL apps to INSTALLED_APPS, such as 'dal_queryset_sequence'

Ergo you need to make sure you configured the INSTALLED_APPS correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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