django - call variable from method inside the method -
having 2 views
views.py
def followup(request): '''''' marklist = report_template(request) return render(request, 'incident/followup.html',{'somevar':somevar}) def report_template(request): ''''' report=report.objects.filter(report=report_id) '''''' return render(request, 'incident/print.html', {'report':report})
i calling 1 method inside method.calling report_template method followup method.followup method have variable render in template.
how pass variable of report_template method followup method , make display in template.
thanks
one way achieve create helper method returns report
or context needed both methods. issue here returning httpresponse
object, , cleanest use helper method here:
def get_report(request): report=report.objects.filter(report=report_id) #do more processing here. #returning dict safest here, because, in calling method, `.get()` not throw error if key not present. return {'report': report, 'somevar': somevar} def followup(request): marklist = get_report(request).get('somevar') return render(request, 'incident/followup.html',{'somevar':marklist}) def report_template(request): report = get_report(request).get('report') return render(request, 'incident/print.html', {'report':report})
Comments
Post a Comment