What is context_object_name in django views?

If you do not provide “context_object_name”, your view may look like this:

<ul>
    {% for publisher in object_list %}
        <li>{{ publisher.name }}</li>
    {% endfor %}
</ul>

But if you provide like {“context_object_name”: “publisher_list”}, then you can write view like:

<ul>
    {% for publisher in publisher_list %}
        <li>{{ publisher.name }}</li>
    {% endfor %}
</ul>

That means you can change the original parameter name(object_list) into any name through “context_object_name” for your view.
Hope that help:)

Leave a Comment

tech