prevent multiple submissions when user clicks submit button multiple times before loading to the new page
<p>I have googled around and it seems like there are many possibilities for php. But I haven't found anything good solution for django. I saw some people using client side javascript code for this, but I just don't get how to fix this. Problem I;m having is:when user writes a post, and click submit button fast twice before new page gets loaded then two posts will be made. Here's my code, thanks in advance.
my html</p>

<pre><code>&lt;form id="post_form" method="post" action="/add_post/" enctype="multipart/form-data"&gt;
    {% csrf_token %}
    {{ form|crispy }}
&lt;input type="submit" name="submit" value="submit"&gt;
&lt;/form&gt;
</code></pre>

<p>my views.py</p>

<pre><code>class PostCreateView(CreateView):

    model = Post
    form_class = PostForm
    template_name = 'main/add_post.html'

    def form_valid(self, form):

        self.object = form.save(commit=False)
        # any manual settings go here

        #self.object.category = Category.objects.filter(category__in=categories).all()

        self.object.moderator = self.request.user
        self.object.image = extract(self.object.url) 
        self.object.thumbnail = extractt(self.object.content)
        self.object.save()
        return HttpResponseRedirect(reverse('post', args=[self.object.slug]))

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        return super(PostCreateView, self).dispatch(request, *args, **kwargs)       
</code></pre>

<p>Edit: I changed it to like this</p>

<pre><code>{% block content %}
&lt;div class="col-sm-5"&gt;
&lt;form id="post_form" method="post" action="/add_post/" enctype="multipart/form-data"&gt;
    {% csrf_token %}
    {{ form|crispy }}
&lt;input type="submit" id="button" name="submit" value="올리기"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;div class="col-sm-4" style="width:400px; height:250px; border:1px solid black;"&gt;
&lt;h3&gt;rule&lt;/h3&gt;

&lt;/div&gt;

&lt;div class="col-sm-3" style="width:420px; height:750px; border:1px solid black;" &gt;
&lt;h3&gt;ad&lt;/h3&gt;
&lt;/div&gt;
    {% endblock %}
&lt;script&gt;
    jQuery('input[name=submit]').on('click', function(){
 if(jQuery(this).hasClass('active')){
   return false;
 }
 else{
  jQuery(this).addClass('active');
 }
});
    &lt;/script&gt;
   {% include 'footer.html' %}
</code></pre>

<p>Final Edit: hope this is right? any suggestion?</p>

<pre><code>import datetime

class PostCreateView(CreateView):

    model = Post
    form_class = PostForm
    template_name = 'main/add_post.html'

    def form_valid(self, form):

        self.object = form.save(commit=False)
        # any manual settings go here

        #self.object.category = Category.objects.filter(category__in=categories).all()

        self.object.moderator = self.request.user
        self.object.image = extract(self.object.url) 
        self.object.thumbnail = extractt(self.object.content)
        self.object.save()

        if not hasattr(self.request.session['last_submitted']):
            self.request.session['last_submitted'] = datetime.datetime.now()
            return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
        else:
            delta = datetime.datetime.now() - self.request.session['last_submitted']
            if delta.seconds &lt; 60: # assume allow re-submit after 60 seconds
                return http.HttpForbidden() #or some other better message??
            else:
                return HttpResponseRedirect(reverse('post', args=[self.object.slug]))

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        return super(PostCreateView, self).dispatch(request, *args, **kwargs) 
</code></pre>

<p>Edit with the solution provided</p>

<pre><code>class PostCreateView(CreateView):

     model = Post
     form_class = PostForm
     template_name = 'main/add_post.html'

     def form_valid(self,form):

        if not hasattr(self.request.session['last_submitted']):
            last_submitted = pickle.dumps(datetime.datetime.now())
            self.request.session['last_submitted'] = last_submitted
            save_it = True
        else:
            last_submitted = pickle.loads(self.request.session['last_submitted'])
            delta = datetime.datetime.now() - last_submitted
            save_it = (delta.seconds &gt; 60) # assume allow re-submit after 60 seconds

        if save_it:
          self.object = form.save(commit=False)
          # any manual settings go here

          #self.object.category =      Category.objects.filter(category__in=categories).all()

          self.object.moderator = self.request.user
          self.object.image = extract(self.object.url) 
          self.object.thumbnail = extractt(self.object.content)
          self.object.save()
          return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
        else:
           # consider redirect as usual, if the user just clicked twice by mistake
           return self.form_invalid(form) # or Http error code
</code></pre>