Reputation: 1353
I built an application with Django that contains a certain number of views. I have to switch from one project to another which use the same views.
For this I used a context processor that returns the variables that change in a dictionnary. Then in all my views I return a context_instance=RequestContext(request)
My problem is that my views do not reload until I click a second time on the button "Change the project".
I don't know if I'm clear enough, but if someone could give me a hint on what is wrong here it would be great. I don't even know what piece of code would help understand the issue, so if you think you can help please ask !
EDIT
A sample of my context_processor
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.template import RequestContext
def display_select_proj(request):
if request.method == "POST" and (request.POST.get("action", "") == "OK"):
form = SelectForm(request.POST, proj_id=request.session['proj'])
if form.is_valid():
p = form.save()
request.session['proj'] = proj
return {'my_variables': my_variables}
Upvotes: 0
Views: 873
Reputation: 5874
Context processor is not a proper place for such kind of logic, especially session modification. You should move it to middleware or view function.
Why your approach doesn't work: context processors just modify the context of template being rendered and are applied after your view function. See "When context processors are applied".
Upvotes: 2