tags:

views:

449

answers:

1

Guys,

I have the following code from some example i got from here, but its not working on my django application.

On my templete i have this function:

$(function(){ setAutoComplete("tags", "tagResults", "/taglookup/?query="); });

and on my urls i have the following line

(r'^taglookup/$', 'twine.twineapp.views.tag_lookup'),

and my view looks like this:

def tag_lookup(request):
    # Default return list
    results = []
    if request.method == "GET":
        if request.GET.has_key(u'query'):
            value = request.GET[u'query']
            # Ignore queries shorter than length 3
            if len(value) > 2:
                #model_results = Book.objects.filter(name__icontains=value)
                TaggedItem = Tag.objects.get_by_model(Question, Tag.objects.filter(name__in=[value]))
                results = [ x.name for x in TaggedItem]
    json = simplejson.dumps(results)
    return HttpResponse(json, mimetype='application/json')

When i try to type anything on my "tags" field in the template, firebug gives me the following error;

GET http://127.0.0.1:8000/taglookup/?query=test 404 NOT FOUND JQuery-1.3.2.js (line 3633)

Any ideas where am goofing?

Gath

+3  A: 

From the 404 error you see in firebug it looks like the request is happening as you expect to the url you told the autocomplete to call. I would double check your urls.py file to make sure there is not an implicit prefix in front of the regex line. Meaning, is that urls line in the base project dir or in an app dir that is is included from the main urls.py file?

If it is included, you might have a line like this in your base urls.py file:

(r'^appname/', include('projectname.appname.urls')),

so then your jQuery function should read:

$(function(){ setAutoComplete("tags", "tagResults", "/appname/taglookup/?query="); });

You can also verify whether the url pattern is working or not by typing that address into your browser, that way you can isolate whether the problem is with the url or jQuery.

dar