views:

485

answers:

2

hello,

anybody knows a tutorial on using jquery file tree browser on django. i followed this tutorial http://abeautifulsite.net/2008/03/jquery-file-tree/ but i cant make it work, im confused with this code block:

    $(document).ready( function() {
            $('#explorer').fileTree({
            root: '/windows/',
             script: 'jqueryFileTree.py',
            expandSpeed: 1000,
            collapseSpeed: 1000,
            multiFolder: True
            }, function(file) {
            alert(file);
    }); 
});

question: in line ==> script: 'jqueryFileTree.py', jqueryFileTree.py on what directory will i put this file?

or maybe can i put the contents of jqueryFileTree.py in my views.py?

A: 

You need to put the jqueryFileTree file into the root of your site or at least on the same level that your site exists. Also make sure that you have a div in your html called Explorer.

You could put it in your views file but you really should not since it wont be cached client side at all unless your page implements caching

RC1140
what do you mean by "root of your site"? is it the directory created by django-admin startproject <project-name> or manage.py <app-name>?am still working locally.
Ron
The root of a site would be www.example.com/ , so it should be the <app-name> location but because of routing this might not always be the case. If possible try to link directly to the file while you are testing , i.e. www.example.com/jqueryFileTree.js
RC1140
A: 

Hi

In django you cannot call directly a python file. You have to create a 'view' in one of your projects apps.

# start your django project
django-admin.py startproject website
# create a first app
django-admin.py startapp explorer

in urls.py you have to create an url mapping :

urlpatterns += patterns('',
    (r'^explore$', 'explorer.views.explore'),
)

in explorer/views.py :

def explore(request):
   # here you create the view that generates the needed html (look the php examples)
   html = 'Hello, <b>World</b>'
   return HttpResponse()

see your blog post for 'custom connectors' details.

In the jQuery explorer config, use '/explore' as script parameter.

Be careful with security with this kind of stuff :)

Note: I would rather use ExtJs for this kind of widgets :)

jujule