title: How do I set initial values on a Django form using CreateView
body: <p>I have a form and wish to set some default values in the fields. My original solution using the <em>View</em> class works</p>
  <pre><code># forms.py
  ResultForm(forms.ModelForm):
  
      class Meta:
          model = Result
          fields = (&quot;date&quot;, &quot;club&quot;, &quot;goals_for&quot;, &quot;goals_against&quot;)
      ...
      @staticmethod
      def get_initial():
          initial = {
              'date': datetime.today().date(),
              'goals_for': 0,
              'goals_against': 0,
          }
          return initial
  </code></pre>
  <p>and</p>
  <pre><code># views.py
  class EnterResultView(View):
      template = 'results/enter_result.html'
  
      def get(self, request):
          form_class = ResultForm()
          form_class.initial = form_class.get_initial()
          context = {
              'form_class': form_class
          }
          return render(request, self.template, context)
  </code></pre>
  <p>But if I convert to a <em>CreateView</em> I cannot get the fields to initialise</p>
  <pre><code># views.py
  class EnterResultView(CreateView):
      template_name = 'results/enter_result.html'
      form_class = ResultForm
      form_class.initial = form_class.get_initial()
  </code></pre>
  <p>What must I do?</p>
  <p>[EDIT added template]</p>
  <pre><code>&lt;!--  results/enter_result.html --&gt;
  ...
          {% for field in view.form_class %}
              &lt;tr&gt;
                  &lt;td style=&quot;text-align: right&quot;&gt;{{ field.label_tag }}&lt;/td&gt;
                  &lt;td&gt;{{ field }}&lt;/td&gt;
                  {% if field.errors %}
                      {% for error in field.errors %}
                          &lt;td class=&quot;form-error&quot;&gt;{{ error }}&lt;/td&gt;
                      {% endfor %}
                  {% endif %}
              &lt;/tr&gt;
          {% endfor %}
  </code></pre>