SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Python Autocomplete Internal 500 error.

    I'm using a Python autocomplete plugin from bassistance.de but I'm receiving a 500 error when typing, instead of suggestions.

    Firebug states a 500 while Python is reporting a name error at line 200 inside my views.py.

    "global name 'HttpResponse' is not defined"

    Error copied from Firebug:
    Code:
    GET http://127.0.0.1:8000/ajax/tag/autocomplete/?q=test&limit=10&timestamp=1262114752504
    	
    500 INTERNAL SERVER ERROR
    		95ms

    Here is my html:
    Code:
    {% block external %}
    	<link rel='stylesheet' type='text/css' href='/site_media/jquery.autocomplete.css' />
    	<script type='text/javascript' src='/site_media/jquery.autocomplete.js'></script>
    	<script type='text/javascript' src='/site_media/tag_autocomplete.js'></script>
    	<script type='text/javascript' src='/site_media/jquery.bgiframe.min.js'></script>
    {% endblock %}
    Here is a snippet from my views.py(line 200 is reporting "global name 'HttpResponse' is not defined"):
    Code:
    def ajax_tag_autocomplete(request):
    	if 'q' in request.GET:
    		tags = Tag.objects.filter(
    			name__istartswith=request.GET['q']
    		)[:10]
    200.		return HttpResponse(u'\n'.join(tag.name for tag in tags))
    	return HttpResponse()
    Here is a snippet from my urls.py:
    Code:
    # Ajax
    (r'^ajax/tag/autocomplete/$', ajax_tag_autocomplete),
    )
    Here is a snippet from my tag_autocomplete.js file:
    Code:
    $(document).ready(function () {
    	$("#id_tags").autocomplete(
    		'/ajax/tag/autocomplete/',
    		{multiple: true, multipleSeparator: ' '}
    	);
    });
    I have a feeling it's something very obvious that I'm overlooking.

    Thanks.

  2. #2
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    enable Django's debug and you'll get details debug information via Firebug

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like you're missing
    Code:
    from django.http import HttpResponse
    in your views.py.

  4. #4
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Derlin View Post
    Looks like you're missing
    Code:
    from django.http import HttpResponse
    in your views.py.
    THANK YOU! I knew it was something obvious like that. Works like a charm now.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •