My "view" code has an obvious repetition in its code. Is there any way of refactoring the "return" code?
def form_contractor_view(request):
if request.method == 'POST':
form = ContractorForm(request.POST)
if form.is_valid():
form.save()
return redirect('index_view')
else:
return render_to_response(
'form_contractor.html',
{'form': form},
context_instance=RequestContext(request),
)
else:
form = ContractorForm()
return render_to_response(
'form_contractor.html',
{'form': form},
context_instance=RequestContext(request),
)