title: Redirect problems with django form in a modal
body: <p>I am trying to implement a form in a modal which is focused on modifying a comment in a post, the way i did it everything works, the problem is when I click on the submit button it sends me to the html in which I have the modal and there I edit the comment. when I try to delete the url in the action form that takes me to the second page of my form it throws the error &quot;local variable 'form' referenced before assign&quot;, also if I put for example in form action the url of the login sends me towards There but the comment is not updated or edited.</p>
  <p>My idea is simply that when I submitting the form, the modal closes, and the page where the modal was opened from the beginning, reload or simply the comment already edited appears.</p>
  <p>if you need more information I can add it.</p>
  <p>views.py</p>
  <pre><code>@need_analyst_role
  def comment_modify(request, comment_id):
  
      if 'comment_edit' in request.POST:
          form_comment = FormComment(request.POST)
          if form_comment.is_valid():
              comment_text = form_comment.cleaned_data['text']
              comment = ModelRiskTracking.objects.get(id=comment_id)
              comment.comment = comment_text
              print(comment.comment)
              comment.save()
  
          else:
              messages.error(request, 'Error!', extra_tags=&quot;danger&quot;)
     
      context = {}
      context['comment'] = ModelRiskTracking.objects.get(id=comment_id)
      
      return render(request, 'analyst_pages/comment_edit.html', context = context)
  </code></pre>
  <p>modal.html</p>
  <pre><code>&lt;div class=&quot;modal-dialog modal-dialog-centered modal-lg&quot; role=&quot;document&quot;&gt;
      &lt;div class=&quot;modal-content&quot;&gt;
          &lt;div class=&quot;modal-header&quot;&gt;
              &lt;h2 class=&quot;modal-title&quot;&gt;Editar comentario&lt;/h2&gt;
              &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                  &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
              &lt;/button&gt;
          &lt;/div&gt;
          &lt;form action=&quot;{% url 'soc_irisk_modify' comment_id=comment.id %}&quot; method=&quot;POST&quot;&gt;
              {% csrf_token %}
              &lt;textarea type=&quot;text&quot; name=&quot;text&quot; class=&quot;form-control&quot; rows=&quot;15&quot;&gt;{{ comment.comment|safe }}&lt;/textarea&gt;
              &lt;div class=&quot;modal-footer&quot;&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Actualizar&quot; name=&quot;comment_edit&quot; onsubmit=&quot;setFormSubmitting()&quot; class=&quot;btn btn-info btn-sm pull-right&quot; /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I open the modal with a button calling a jQuery function:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
      function openModal(url){
          $('#commentModal').load(url, function(){
              $(this).modal('show');
          });
      }
  &lt;/script&gt;
  
  
  &lt;button type=&quot;button&quot; class=&quot;btn btn-primary btn-sm pull-right&quot; data-toggle=&quot;modal&quot; data-target=&quot;#commentModal&quot; onclick=&quot;openModal('{% url 'soc_comment_modify' comment_id=comment.id %}')&quot;&gt;
  </code></pre>