In Django, the canonical way of processing forms is:
if request.method == 'POST':
form = SomeForm(request.POST)
if form.is_valid():
use the form data
I want to execute the same code whether there was no POST or the form was invalid – it’s a few lines of code, so I’m wondering if there is a nicer way of doing this than having two duplicate else blocks (one for the inner if and one for the outer)?
A very concise way that does not require a separate function, and doesn’t repeat conditions: