[Django]-Django-smart-selects doesn't work in templates

6πŸ‘

βœ…

Here’s how I solved this, for some reason unknown to me, a file called chainedfk.js is missing. After a little digging I found that this file exists in this path β€˜smart-selects/admin/js/chainedfk.js’ in the library files.
So I simply added this import line my base.html file.

*I removed the tags so it can be visible.

script src=”{% static β€˜smart-selects/admin/js/chainedfk.js’ %}”

after the js import line and it worked like a charm πŸ™‚

πŸ‘€Lantern

2πŸ‘

UPDATE – MAY- 2017

Sorry, things have a bit changed as of now, my form also refused to load and yet it was loading some time back, so you have to include the tag below, right after the jquery and the tag that contains chainedfk.js

This works very well both for django 1.10.5 and Django 1.11 -(the latest version as of this writting) – Python 3.5.2

<script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
<script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
<script type="text/javascript" src="{% static 'smart-selects/admin/js/bindfields.js' %}"></script>
πŸ‘€dungu

0πŸ‘

I had the same problem but without receiving any error.
it worked for me too when I included:

<script src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
πŸ‘€George

0πŸ‘

to be 100% correct you have to import file with this specific order:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js </script>
<!-- Smart select -->
<script src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
<script src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
πŸ‘€George

0πŸ‘

Worked for me by putting {{form.media.js}} which loads the required javascripts in the head.
so:

{% block headjavascript %}{{ form.media.js }}{% endblock %}

Which is a better practice for loading javascript

Leave a comment