title: How to output to a text file with indentation
body: <p>I'm new to Django and am trying to output the results of a form to a text file with indentation. I have read the documentation and can only find a writer for writing CSV output. Ultimately I'm trying to generate a downloadable Python script based on inputs from a form. Since the Python requires accurate indentation, I'm having trouble outputting correctly. </p>
  
  <p>Here is part of my view that im using to generate output:</p>
  
  <pre><code>if form.is_valid():
          ServerName = form.cleaned_data.get('ServerName')
          response = HttpResponse(mimetype='text/plain')
          response['Content-Disposition'] = 'attachment; filename=script.py' 
          writer = csv.writer(response)
          writer.writerow(['def ping ():'])
          writer.writerow(['run ('ping ServerName')])
  return response
  </code></pre>
  
  <p>I would like the output of the script.py to be like this:</p>
  
  <pre><code>def ping():
      run('ping server01')
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>Am I using the correct writer to output to a text file?</li>
  <li>How do I add indentation to my output?</li>
  <li>How to I add brackets i.e.: <code>( )</code>  or quotes <code>' '</code> to the output without getting errors in the view.</li>
  </ol>
  
  <p>Thanks.</p>