1

I am using a JavaScript (jQuery FileTree, see here: http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/) inside my Django application. The problem is, this JavaScript needs the path to a python script. How can I realise this? I can not use Django template tags inside JavaScript.

In my html template I have:

    {% load staticfiles %}
    <script src={% static "treeview.js" %} type="text/javascript"></script>

And this is the JavaScript treeview.js (which is loaded correctly):

    $(document).ready(function() {

        $('#file_selector').fileTree({
        root: '/',

        // how to load this file? 
        script: 'path/to/python/script.py',

        folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750,
        expandEasing: 'easeOutBounce',
        collapseEasing: 'easeOutBounce', loadMessage: 'Laden...',
        multiFolder: false},

        function(file) { alert(file); }
        );

    });

Django will not find the script path/to/python/script.py, how can I serve this file? Maybe I have not yet fully understood the concept of static files in Django? Note that the script doesn't have to be python, I want to know how to load an arbitrary file inside my JavaScript.

1
  • I would either route the file through urls.py or send off an ajax-request to a lookup function on your backend that would answer with the file in question. Commented Jul 7, 2014 at 9:33

1 Answer 1

0

You've misunderstood what the "script" parameter is. It's not a file path to a script, it's a URL: the location of the server-side code that returns the JSON to populate the treeview. You need to write a view and connect it with your urlconf, then use that URL in the JS options.

Note that that package apparently already includes a connector for Django. Also you might want to reflect that there are probably better options for a file browser than an unmaintainted six-year-old package.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.