title: POST method of FormView in Django?
body: <p>Edit: just used a new listing for when user submits the user to search on though I am not sure how to get what user was submitted still in my QueryUser class (the id of 24 is just a test, oh and I tried to add pagination but ripped it out because it would break when someone clicked a new page, would go back to the Query.html posted below, the crispy forms not the data returned)</p>
  <pre><code>class QueryUser(LoginRequiredMixin, FormView):
      model = OnSiteLog
      form_class = QueryForm
      template_name = 'log/query.html'
      success_url = '/'
      def form_valid(self, form, *args, **kwargs):
          user = form.cleaned_data.get('user')
  
      def post(self, request, *args, **kwargs):
          object_list = OnSiteLog.objects.filter(user_id=24).order_by('-checkIn')
          super(QueryUser, self).post(request, *args, **kwargs)
          page = request.GET.get('page', 1)
  
          paginator = Paginator(object_list, 10) # 3 posts in each page
        #make a map into the object list
        
          try:
              log_pages = paginator.page(page)
          except PageNotAnInteger:
              # If page is not an integer deliver the first page
              log_pages = paginator.page(1)
          except EmptyPage:
              # If page is out of range deliver last page of results
              log_pages = paginator.page(paginator.num_pages)
  
          return render(request, 'log/query2.html', {'page':page, 'log':object_list, 'object_list':log_pages})
  </code></pre>
  <p>I am tring to understand how works <strong>Class Based Views</strong> in Django. I have next working code with <code>View</code>. I want to write that code with the help of <code>FormView</code>. Is my `FormView code correct? I need someone who can analyze that code and say where is my mistakes. I would be grateful for any help.</p>
  <p>Right now <code>get method</code> works. The problem is when I try to <code>submit</code> form. Form dont disappear. In the same time in console I see this url: <code>&quot;POST /url/ HTTP/1.1&quot; 200 1891</code>. In database I see that new article was created. How to fix this strange problem with <code>post method</code>?</p>
  <p><strong>CBV with View:</strong></p>
  <pre><code>class ArticleCreateView(FormView):
      template_name = 'article/create_article.html'
      form_class = ArticleForm
  
      def post(self, request):
          data = dict()
          article_create_form = ArticleForm(request.POST, request.FILES)
          if article_create_form.is_valid():
              article_create_form.save()
              data['form_is_valid'] = True
              context = {
                  'articles': Article.objects.all()
              }
              data['html_articles'] = render_to_string(
                  'article/articles.html',
                  context
              )
          else:
              data['form_is_valid'] = False
          return JsonResponse(data)
  
      def get(self, request):
          data = dict()
          article_create_form = ArticleForm()
          context = {
              'article_create_form': article_create_form
          }
          data['html_article_create_form'] = render_to_string(
              'article/create_article.html',
              context,
              request=request
          )
          return JsonResponse(data)
  </code></pre>
  <p><strong>CBV with FormView:</strong></p>
  <pre><code>class ArticleCreateView(FormView):
      template_name = 'article/create_article.html'
      form_class = ArticleForm
      form_dict = {
          'Article_create_form': ArticleForm
      }
  
      def get(self, request):
          data = dict()
          context = {'article_create_form': ArticleForm()}
          data['html_article_create_form'] = render_to_string(
              'article/create_article.html', context, request=request
          )
          return JsonResponse(data)
  
      def form_valid(self, form):
          data = dict()
          self.object = form.save()
          context = {'articles': Article.objects.all()}
          data['html_articles'] = render_to_string(
              'article/articles.html',
              context
          )
          return JsonResponse(data)
  </code></pre>
  <p>EDIT Article FormView code:</p>
  <pre><code>class ArticleEditView(FormView):
      template_name = 'article/edit_article.html'
      form_class = ArticleForm
  
      def get(self, request, pk):
          data = dict()
          context = {
              'article': Article.objects.get(pk=pk),
              'article_edit_form': ArticleForm(instance=Article.objects.get(pk=pk))
          }
          data['html_article_edit_form'] = render_to_string(
              'article/edit_article.html', context, request=request
          )
          return JsonResponse(data)
  
      def form_valid(self, form):
          form.save()
          data = dict()
          data['form_is_valid'] = True
          context = {'articles': Article.objects.all()}
          data['html_articles'] = render_to_string('article/articles.html', context)
          return JsonResponse(data)
  </code></pre>
  <p><strong>ERROR:</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/core/handlers/exception.py&quot;, line 41, in inner
      response = get_response(request)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/core/handlers/base.py&quot;, line 217, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/core/handlers/base.py&quot;, line 215, in _get_response
      response = response.render()
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/response.py&quot;, line 107, in render
      self.content = self.rendered_content
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/response.py&quot;, line 84, in rendered_content
      content = template.render(context, self._request)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/backends/django.py&quot;, line 66, in render
      return self.template.render(context)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/base.py&quot;, line 207, in render
      return self._render(context)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/base.py&quot;, line 199, in _render
      return self.nodelist.render(context)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/base.py&quot;, line 990, in render
      bit = node.render_annotated(context)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/base.py&quot;, line 957, in render_annotated
      return self.render(context)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/template/defaulttags.py&quot;, line 458, in render
      url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/urls/base.py&quot;, line 91, in reverse
      return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
    File &quot;/srv/envs/py27/lib/python2.7/site-packages/django/urls/resolvers.py&quot;, line 497, in _reverse_with_prefix
      raise NoReverseMatch(msg)
  NoReverseMatch: Reverse for 'article_edit' with arguments '('',)' not found. 1 pattern(s) tried: [u'administration/article/(?P&lt;pk&gt;\\d+)/edit/$']
  </code></pre>
  <p><strong>articles.html:</strong></p>
  <pre><code>{% for article in articles %}
  &lt;div class=&quot;list-group-item&quot; data-id='{{ article.id }}'&gt;
     &lt;button class=&quot;btn slideEditBtn&quot; data-url=&quot;{% url 'article:article_edit' pk=slide.id %}&quot;&gt;
          &lt;i class=&quot;fa fa-pencil&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt;
      &lt;/button&gt;
  &lt;/div&gt;
  {% endfor %}
  </code></pre>