Saturday, August 10, 2013

Re: django ajax runtime error - URL doesn't end in slash

Can you paste the markup for your search form?

Sent from my iPhone

On Aug 10, 2013, at 11:46 AM, Robin Lery <robinlery@gmail.com> wrote:

I am practicing from a tutorial where I have reached to create a search box with jquery and ajax. Every thing is going good, except, when i press any key in the search, I get an error,

RuntimeError at /articles/search You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to localhost:8000/articles/search/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.

I checked for "/" in my code, but its there. Don't know what's going on. Please help.

application's urls.py:

    url(r'^search/$', 'article.views.search_title'),  )

views.py:

def search_title(request):      if request.method == "POST":          search_text = request.POST['search_text']      else:          search_text = ''        articles = Article.objects.filter(title__contains=search_text)        return render_to_response('ajax_search.html', {'article': article})

I'm using jquery version: jquery-2.0.0.min.js

ajax.js:

$(function(){        $('#search').keyup(function() {            $.ajax({              type: "POST",              url: '/articles/search/',              data: {                   'search_text' : $('#search').val(),                  'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val()              },              success: searchSuccess,              dataType: 'html'          });        });    });    function searchSuccess(data, textStatus, jqXHR)  {      $('#search-results').html(data);  }

And even when I inspect the ajax.js, in the last line

$('#search-results').html(data);

It reads it as:

$('#search-results').html(date);

Please help me somebody. Thank you.

My main url:

(r'^articles/', include('article.urls')),

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate