On Jan 10, 3:35 am, neridaj <neri...@gmail.com> wrote:
> I'm trying to use a context processor to make all of my blog entry
> titles available for an ajax autocomplete search box but for some
> reason the var returned from the context processor is empty.
>
> from blog.models import Entry
>
> # search/context_processors.py
>
> def search(request):
>         data = Entry.objects.all()
>         return { 'data': data }
>
> # settings.py
>
> TEMPLATE_CONTEXT_PROCESSORS = (
>     "django.core.context_processors.auth",
>     "django.core.context_processors.debug",
>     "django.core.context_processors.i18n",
>     "django.core.context_processors.media",
>     "search.context_processors.search",
> )
>
> # base.html
>
>     <script>
>         $(document).ready(function(){
>             var data = "{{ data }}".split(":");
>             $("#id_q").autocomplete(data);
>         });
>     </script>
>
> # base.html rendered
>
>  $(document).ready(function(){
>     var data = "".split(":");
>     $("#id_q").autocomplete(data);
>    });

It's not AJAX if you're hard-coding all the entries into the template,
it's just basic Javascript, but never mind.

You don't show how you're rendering that template, but I suspect that
you're not using RequestContext.

Bear in mind that the context processor is run for *every single view*
(again, as long as you use RequestContext), which may not be what you
want. I'd suggest a template tag for this use case. Or you could
actually make it Ajax, so it requests matching entries dynamically.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to