title: Django model CreateView does not render form fields in HTML
body: <p>I am trying to setup a class based 'CreateView' for a model in my django site, but when the create html page renders, the model fields are not rendered. Only the submit button shows up on the web page. However, when debugging, I overrided the 'form_invalid' method in the class view, and the form object had the required HTML for all fields stored in the object. If I take this HTML and manually add it to the HTML of the create page in the browser I can fill out the fields and post the data to the database.</p>
  
  <p>At this point I have not found an obvious answer as to why the form fields are not rendered so any help on this would be greatly appreciated.</p>
  
  <p>environment used: python 3.7.3, django 2.2.3</p>
  
  <hr>
  
  <p><strong>Solution:</strong></p>
  
  <p>This issue was fixed by changing the form name in the view context data.</p>
  
  <p>In views.py:</p>
  
  <pre><code>
  def get_context_data(self, *args, **kwargs):
          context = super(CreateAlertView, self).get_context_data(**kwargs)
          context["alert_form"]=context["form"]
          return context
  </code></pre>
  
  <p>Or...
  In the HTML template change 'alert_form' to 'form' to match the default context.</p>
  
  <hr>
  
  <p>models.py:</p>
  
  <pre><code>class Alert(models.Model):
      RAIN = 'Rain'
      SNOW = 'Snow'
      COLD = 'Cold'
      HEAT = 'Heat'
      WEATHER_CHOICES = [
          (RAIN, 'Rain'),
          (SNOW, 'Snow'),
          (COLD, 'Cold'),
          (HEAT, 'Heat'),
      ]
  
      DAILY = 'Daily'
      WEEKLY = 'Weekly'
      INTERVAL_CHOICES = [
          (DAILY, 'Daily'),
          (WEEKLY, 'Weekly'),
      ]
  
      weather_type = models.CharField(max_length=15, choices=WEATHER_CHOICES, default=RAIN)
      interval = models.CharField(max_length=10, choices=INTERVAL_CHOICES, default=DAILY)
      search_length = models.IntegerField(default=1)
      user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
      active = models.BooleanField(default=False)
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>class CreateAlertView(LoginRequiredMixin, CreateView):
      template_name = 'users/alert_form.html'
      #model = Alert
      form_class = AlertModelForm
      success_url = 'users/profile/'
  
      def form_valid(self, form):
  
          print('validation')
          form.instance.user = self.request.user
          return super().form_valid(form)
  
      def form_invalid(self, form):
          print(form) # check form HTML here
          return super().form_invalid(form)
  </code></pre>
  
  <p>forms.py:</p>
  
  <pre><code>class AlertModelForm(ModelForm):
  
      class Meta:
          model = Alert
          exclude = ['user']
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>urlpatterns = [
      path('alert/create/', CreateAlertView.as_view(), name='alert'),
  ]
  </code></pre>
  
  <p>html template:</p>
  
  <pre><code>&lt;h1&gt;create an alert&lt;/h1&gt;
  &lt;form method="post"&gt;
      {% csrf_token %}
      {{ alert_form.as_p }}
      {{ alert_form.non_field_errors }}
      {{ field.errors }}
      &lt;button type="submit"&gt;Save changes&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Create page as rendered:</p>
  
  <p><a href="https://i.stack.imgur.com/wiTy3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wiTy3.png" alt="Create page as rendered"></a></p>
  
  <p>Create page with manually modified HTML:
  <a href="https://i.stack.imgur.com/ncnpX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ncnpX.png" alt="Create page with manually modified HTML"></a></p>