Code

Opened 4 years ago

Closed 3 years ago

#14792 closed Cleanup/optimization (invalid)

error in the default for TEMPLATE_CONTEXT_PROCESSORS

Reported by: lawgon@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: settings TEMPLATE_CONTEXT_PROCESSORS
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In this page, a list of context processors is given as the default for TEMPLATE_CONTEXT_PROCESSORS. But the generated settings file does not have TEMPLATE_CONTEXT_PROCESSORS at all. So either the default is set as empty, or the generated settings file should have the default values.

Attachments (0)

Change History (7)

comment:1 Changed 4 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This isn't technically an error - if settings.py doesn't have TEMPLATE_CONTEXT_PROCESSORS it is taken from django/conf/global_settings.py, which does set it to the list given in the documentation.

The issue is that if you need to add something to TEMPLATE_CONTEXT_PROCESSORS, you need to copy from global_settings.py and then change. There are other similar settings for which we do this (like FILE_UPLOAD_HANDLERS, IGNORABLE_404_ENDS), but changing TEMPLATE_CONTEXT_PROCESSORS is probably going to be more common, and I imagine it would be more common than things like STATICFILES_FINDERS which is in the project template, so we should include this.

comment:2 Changed 4 years ago by lawgon

actually I noticed this problem because request was not available in the template even though I was passing it through RequestContext. It only became available when I added the requisite TEMPLATE_CONTEXT_PROCESSOR in settings.py. Apparently it does not take it from global_settings.py. I have seen this on about 4 sites in different locations and platforms. Just looked at global_settings.py and find that 'django.core.context_processors.request' has been commented out - that looks like the source of my problem.

comment:3 Changed 4 years ago by lukeplant

The fact that the 'request' context processor is missing in global_settings.py is not a bug. The default list of context processors is the same as that in the docs. Apps that require the 'request' context processor need to state that they do. I guess the reason it is there and commented out is to make it easy for people to copy/paste and add it. The project template should probably have the same thing.

comment:4 Changed 3 years ago by anonymous

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:5 follow-up: Changed 3 years ago by lawgon

  • Easy pickings unset
  • UI/UX unset

Since this comes up at least a couple of times a week on IRC, and seems to me a pretty common requirement, why not just uncomment it and add that fact to the docs?

comment:6 in reply to: ↑ 5 Changed 3 years ago by ramiro

Replying to lawgon:

actually I noticed this problem because request was not available in the template even though I was passing it through RequestContext. It only became available when I added the requisite TEMPLATE_CONTEXT_PROCESSOR in settings.py. Apparently it does not take it from global_settings.py. I have seen this on about 4 sites in different locations and platforms. Just looked at global_settings.py and find that 'django.core.context_processors.request' has been commented out - that looks like the source of my problem.

Exactly, and what you'd need to do to solve that is what Luke suggested: Copy the default value from global_settings.py or from the TEMPLATE_CONTEXT_PROCESSORS setting documentation and customize its value for your needs.

Replying to lawgon:

Since this comes up at least a couple of times a week on IRC, and seems to me a pretty common requirement, why not just uncomment it and add that fact to the docs?

It is not clear to me which is exactly the issue that comes up at least a couple of times a week on IRC?

comment:7 Changed 3 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

Closing this because it doesn't appear to be a bug.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.