Sunday, 15 January 2012

django - Can not see the result of query in template -



django - Can not see the result of query in template -

i want see query results in html after ajax request. please find code below, def tanim_ajax(request):

#views.py def tanim_ajax(request): if request.get.get('q'): q = request.get.get('q') results = title.objects.filter(title__contains=q), print results homecoming render_to_response('tanim/ajax.html', {'results':results}, context_instance=requestcontext(request)) #models.py class title(models.model): title = models.charfield(max_length=100,verbose_name="başlık") category = models.foreignkey(category,verbose_name="kategori") active = models.booleanfield(default=false) slug = models.slugfield(editable=false) def __unicode__(self): homecoming self.title

everything works fine template

{% in results %} <br>{{i}} {% endfor %}

i can see result [<title: foo>] when checked thehttp://127.0.0.1:8000/tanimlar/tanim_ajax/?q=foourl.

but when have next template

{% in results %} <br>{{i.title}} {% endfor %}

i dont see results. thought ?

because you're passing queryset context. instead, seek appending values() query homecoming dictionary.

results = title.objects.filter(title__contains=q).values()

django django-views django-templates

No comments:

Post a Comment