Reputation: 31
Im working on project and im sending data/veriable while redirecting flow from one view to another(first view/empty view)
def index(request,a=False):
if request.method=='POST':
return render(request,'chart-chart-js.html',{'a':True})
return render(request,'chart-chart-js.html',{'a':a})
def login(request):
if request.method == 'POST':
form = NameForm(request.POST)
if form.is_valid():
if form.cleaned_data['username']=='Unknown' and form.cleaned_data['password']=='Unknown':
return redirect(index,a=True)
Upvotes: 0
Views: 24
Reputation: 133
You can not pass context variables using Redirect this way.
I can suggest two options:
In login function:
return redirect(reverse(index) + '?a=VALUE')
In index function:
a = request.GET.get('a')
In login function:
request.session['a'] = VALUE
return redirect(index)
In index function:
a = request.session.get('a')
Upvotes: 1