Fix Django syntax errors and improve template formatting