title: DJANGO - local variable 'form' referenced before assignment
body: <p>I'm trying to make a form get information from the user and use this information to send a email. Here's my code:</p>
  
  <pre><code>#forms.py
  from django import forms
  
  class ContactForm(forms.Form):
      nome = forms.CharField(required=True)
      email = forms.EmailField(required=True)
      msg = forms.CharField(
          required=True,
          widget=forms.Textarea
      )
  
  #views.py
  from django.shortcuts import render, redirect, get_object_or_404, HttpResponseRedirect, render_to_response
  from django.core.mail import send_mail
  from .forms import ContactForm
  
  def contato(request):
      form_class = ContactForm
      if request.method == 'POST':
          form = form_class(request.POST)
          if form.is_valid():
              nome = request.POST.get('nome')
              email = request.POST.get('email')
              msg = request.POST.get('msg')
  
              send_mail('Subject here', msg, email, ['testmail@gmail.com'], fail_silently=False)
              return HttpResponseRedirect('blog/inicio')
      return render(request, 'blog/inicio.html', {'form': form})
  
  
  #contato.html
  {% extends "blog/base.html" %}
  {% block content %}
  
                      &lt;form role="form" action="" method="post"&gt;
                          {% csrf_token %}
                          {{ form.as_p }}
                          &lt;button type="submit"&gt;Submit&lt;/button&gt;
                      &lt;/form&gt;
  {% endblock %}
  </code></pre>
  
  <p>and when I try to enter in contact page I get this error:</p>
  
  <pre><code>local variable 'form' referenced before assignment
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/utld3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/utld3.png" alt="enter image description here"></a></p>
  
  <p>It is saying tha the error is in this line of views.py:</p>
  
  <pre><code>return render(request, 'blog/inicio.html', {'form': form})
  </code></pre>
  
  <p>I'm a little new on Django, can you please help me?</p>