[Answer]-Variable in Django Context Processor

1👍

The code you’ve shown us looks ok to me. You need to make sure that your view (which you haven’t shown) is rendering the template using a request context. See the docs for more information.

Add logging or print statements to your context processor to make sure it is running in your view. Perhaps there are no interview objects in your database, so it’s returning an empty queryset.

Another option to aid debugging is to install the Django debug toolbar. It has a Template panel which shows you the output of your template context processors.

Another couple of suggestions:

  • name your model Interview, and use underscores for your method new_message and variable get_message_value names.
  • put your context processor in a separate module userprofile.context_processors instead of in your views module.

If you follow these conventions, your code is much easier for experienced python and Django developers to read, so you’re more likely to get answers to your questions.

Leave a comment