javascript - value gets submitted through form, then even after the value got submitted and gets displayed, in a form the value got submitted is shown -


sorry long title, happens: submit word "hello", hello gets displayed. in form, still says "hello". i'm not sure why happening. django problem or javascript code needed this...?here's full code think causing problem. in views.py

def post(request, slug):         user = get_object_or_404(user,username__iexact=request.user)         try:             profile = myprofile.objects.get(user_id=request.user.id)             # if it's onetoone field, can do:             # profile = request.user.myprofile         except myprofile.doesnotexist:             profile = none         post = get_object_or_404(post, slug=slug)         post.views += 1  # increment number of views         post.save()      # , save         path = request.get_full_path()         comments = comment.objects.filter(path=path)         #comments = post.comment_set.all()         comment_form = commentform(request.post or none)         if comment_form.is_valid():             parent_id = request.post.get('parent_id')             parent_comment = none             if parent_id not none:                 try:                     parent_comment = comment.objects.get(id=parent_id)                 except:                     parent_comment = none             comment_text = comment_form.cleaned_data['comment']             new_comment = comment.objects.create_comment(                 user=myprofile.objects.get(user=request.user),                 path=request.get_full_path(),                 text=comment_text,                 post = post,                 parent = parent_comment)          c in comments:             c.get_children()           context_dict = {             'post' :post,             'profile' :profile,             'comments' : comments,             'comment_form':comment_form          }          return render(request, 'main/post.html', context_dict) 

and in post.html have

<table class='table'>  {% comment in comments %}  <tr><td>{{ comment.get_comment }}  <br/><small>via {{ comment.user }} | {{ comment.timestamp|timesince }} ago </small>         {% if not comment.is_child %}         <ul>         {% child in comment.get_children %}         <li>{{ child.get_comment }}          <small>via {{ child.user }}</small>           </li>         {% endfor %}         </ul>         <a href='#' class='reply_btn'>reply</a>         <div class='reply_comment'>         <form method="post" action=''>{% csrf_token %}         <input type='hidden' name='parent_id' value='{{ comment.id }}' />         {{ comment_form.as_p }}         <input type='submit' class='btn btn-default' value='add reply'/>         </form>         </div>         {% endif %}   </td></tr>  {% endfor %}  </table> </div>    <div class = "col-sm-3">  </div>      {% include 'footer.html' %}   <script> {% block jquery %} $('.reply_btn').click(function(e){   e.preventdefault();   $(this).next(".reply_comment").fadetoggle();   // $(".reply_comment").fadetoggle(); }) {% endblock %} </script>  {% endblock %} 

can please direct me should look.....thank you

before check if form valid or not assign form include post data still include when return form (in case needs show errors). easiest fix reassign form after valid logic done.

   comment_form = commentform(request.post or none)     if comment_form.is_valid():         .. valid logic ..         comment_form = commentform() 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -