Can't refresh the page after form submissionSaving form data rewrites the same rowDjango low level cache viewsHandling request in django inclusion template tagCan't assign a value (user id) to a ForeignKey fieldUse django comments on article's comment page (/a/2/comments/)Django POST request to my view from Pyres worker - CSRF tokenDjango redirects to login page even after logging indjango: Passing posted files through HttpResponseRedirectWhy calling method inside views.py after successful submission of forms doesn't clear the form?Django2: After form submission is there a better way to 'wipe' the POST to stop re-submission

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Closed subgroups of abelian groups

Can I make popcorn with any corn?

A function which translates a sentence to title-case

What Brexit solution does the DUP want?

least quadratic residue under GRH: an EXPLICIT bound

Showing the closure of a compact subset need not be compact

Why is an old chain unsafe?

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

Email Account under attack (really) - anything I can do?

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?

Copenhagen passport control - US citizen

A Journey Through Space and Time

Can you lasso down a wizard who is using the Levitate spell?

Prevent a directory in /tmp from being deleted

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

What is GPS' 19 year rollover and does it present a cybersecurity issue?

Finding files for which a command fails

Non-Jewish family in an Orthodox Jewish Wedding

Need help identifying/translating a plaque in Tangier, Morocco

What is the meaning of "of trouble" in the following sentence?

Schwarzchild Radius of the Universe

Draw simple lines in Inkscape

Are white and non-white police officers equally likely to kill black suspects?



Can't refresh the page after form submission


Saving form data rewrites the same rowDjango low level cache viewsHandling request in django inclusion template tagCan't assign a value (user id) to a ForeignKey fieldUse django comments on article's comment page (/a/2/comments/)Django POST request to my view from Pyres worker - CSRF tokenDjango redirects to login page even after logging indjango: Passing posted files through HttpResponseRedirectWhy calling method inside views.py after successful submission of forms doesn't clear the form?Django2: After form submission is there a better way to 'wipe' the POST to stop re-submission






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am building a comment system in a blog like Django project. There is a form at the end of each article (that works fine). I want to make it so that when the form is submitted, the page refreshes and the comment is visible.



(Before I just linked to the front page of the blog, and the comments were saved and displayed)



I try the code below, but the page is stuck in "loading", then displays a ip_adress can't be reached, but nevertheless writes the DB. This is my views.py



def view_article(request, id):
try:
article =get_object_or_404(Article, id=id)
comments = CommentArticle.objects.filter(article_id=id)
form = CommentForm(request.POST or None, initial='article_id': id)
url = "submit_comment/" + str(id)
if form.is_valid():
message = form.cleaned_data['message']
poster_name = form.cleaned_data['poster_name']
article_id = id
return HttpResponseRedirect(reverse('refresh_article'))

except Article.DoesNotExist:
raise Http404

return render( request, 'blog/view_article.html', locals())

def refresh_article(request, id):
url = 'view_article' + str(id)
return HttpResponseRedirect(reverse(url))


Does anyone has any clue? Thanks !










share|improve this question




























    0















    I am building a comment system in a blog like Django project. There is a form at the end of each article (that works fine). I want to make it so that when the form is submitted, the page refreshes and the comment is visible.



    (Before I just linked to the front page of the blog, and the comments were saved and displayed)



    I try the code below, but the page is stuck in "loading", then displays a ip_adress can't be reached, but nevertheless writes the DB. This is my views.py



    def view_article(request, id):
    try:
    article =get_object_or_404(Article, id=id)
    comments = CommentArticle.objects.filter(article_id=id)
    form = CommentForm(request.POST or None, initial='article_id': id)
    url = "submit_comment/" + str(id)
    if form.is_valid():
    message = form.cleaned_data['message']
    poster_name = form.cleaned_data['poster_name']
    article_id = id
    return HttpResponseRedirect(reverse('refresh_article'))

    except Article.DoesNotExist:
    raise Http404

    return render( request, 'blog/view_article.html', locals())

    def refresh_article(request, id):
    url = 'view_article' + str(id)
    return HttpResponseRedirect(reverse(url))


    Does anyone has any clue? Thanks !










    share|improve this question
























      0












      0








      0








      I am building a comment system in a blog like Django project. There is a form at the end of each article (that works fine). I want to make it so that when the form is submitted, the page refreshes and the comment is visible.



      (Before I just linked to the front page of the blog, and the comments were saved and displayed)



      I try the code below, but the page is stuck in "loading", then displays a ip_adress can't be reached, but nevertheless writes the DB. This is my views.py



      def view_article(request, id):
      try:
      article =get_object_or_404(Article, id=id)
      comments = CommentArticle.objects.filter(article_id=id)
      form = CommentForm(request.POST or None, initial='article_id': id)
      url = "submit_comment/" + str(id)
      if form.is_valid():
      message = form.cleaned_data['message']
      poster_name = form.cleaned_data['poster_name']
      article_id = id
      return HttpResponseRedirect(reverse('refresh_article'))

      except Article.DoesNotExist:
      raise Http404

      return render( request, 'blog/view_article.html', locals())

      def refresh_article(request, id):
      url = 'view_article' + str(id)
      return HttpResponseRedirect(reverse(url))


      Does anyone has any clue? Thanks !










      share|improve this question














      I am building a comment system in a blog like Django project. There is a form at the end of each article (that works fine). I want to make it so that when the form is submitted, the page refreshes and the comment is visible.



      (Before I just linked to the front page of the blog, and the comments were saved and displayed)



      I try the code below, but the page is stuck in "loading", then displays a ip_adress can't be reached, but nevertheless writes the DB. This is my views.py



      def view_article(request, id):
      try:
      article =get_object_or_404(Article, id=id)
      comments = CommentArticle.objects.filter(article_id=id)
      form = CommentForm(request.POST or None, initial='article_id': id)
      url = "submit_comment/" + str(id)
      if form.is_valid():
      message = form.cleaned_data['message']
      poster_name = form.cleaned_data['poster_name']
      article_id = id
      return HttpResponseRedirect(reverse('refresh_article'))

      except Article.DoesNotExist:
      raise Http404

      return render( request, 'blog/view_article.html', locals())

      def refresh_article(request, id):
      url = 'view_article' + str(id)
      return HttpResponseRedirect(reverse(url))


      Does anyone has any clue? Thanks !







      django django-forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 1:11









      Theau PoulatTheau Poulat

      263




      263






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You're entering an infinite loop. You need to only validate the form on the post.



          def view_article(request, id):
          try:
          article =get_object_or_404(Article, id=id)
          comments = CommentArticle.objects.filter(article_id=id)
          form = CommentForm(request.POST or None, initial='article_id': id)
          url = "submit_comment/" + str(id)
          if request.method == "POST" and form.is_valid():
          message = form.cleaned_data['message']
          poster_name = form.cleaned_data['poster_name']
          article_id = id
          return HttpResponseRedirect(reverse('view_article', kwargs='id': id))

          except Article.DoesNotExist:
          raise Http404

          return render( request, 'blog/view_article.html', locals())


          Also, you don't need to redirect to another view, to redirect back to the current view. You can simply just redirect back to the same view.






          share|improve this answer

























          • Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

            – Theau Poulat
            Mar 22 at 15:35












          • You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

            – schillingt
            Mar 22 at 16:13











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291489%2fcant-refresh-the-page-after-form-submission%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You're entering an infinite loop. You need to only validate the form on the post.



          def view_article(request, id):
          try:
          article =get_object_or_404(Article, id=id)
          comments = CommentArticle.objects.filter(article_id=id)
          form = CommentForm(request.POST or None, initial='article_id': id)
          url = "submit_comment/" + str(id)
          if request.method == "POST" and form.is_valid():
          message = form.cleaned_data['message']
          poster_name = form.cleaned_data['poster_name']
          article_id = id
          return HttpResponseRedirect(reverse('view_article', kwargs='id': id))

          except Article.DoesNotExist:
          raise Http404

          return render( request, 'blog/view_article.html', locals())


          Also, you don't need to redirect to another view, to redirect back to the current view. You can simply just redirect back to the same view.






          share|improve this answer

























          • Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

            – Theau Poulat
            Mar 22 at 15:35












          • You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

            – schillingt
            Mar 22 at 16:13















          0














          You're entering an infinite loop. You need to only validate the form on the post.



          def view_article(request, id):
          try:
          article =get_object_or_404(Article, id=id)
          comments = CommentArticle.objects.filter(article_id=id)
          form = CommentForm(request.POST or None, initial='article_id': id)
          url = "submit_comment/" + str(id)
          if request.method == "POST" and form.is_valid():
          message = form.cleaned_data['message']
          poster_name = form.cleaned_data['poster_name']
          article_id = id
          return HttpResponseRedirect(reverse('view_article', kwargs='id': id))

          except Article.DoesNotExist:
          raise Http404

          return render( request, 'blog/view_article.html', locals())


          Also, you don't need to redirect to another view, to redirect back to the current view. You can simply just redirect back to the same view.






          share|improve this answer

























          • Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

            – Theau Poulat
            Mar 22 at 15:35












          • You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

            – schillingt
            Mar 22 at 16:13













          0












          0








          0







          You're entering an infinite loop. You need to only validate the form on the post.



          def view_article(request, id):
          try:
          article =get_object_or_404(Article, id=id)
          comments = CommentArticle.objects.filter(article_id=id)
          form = CommentForm(request.POST or None, initial='article_id': id)
          url = "submit_comment/" + str(id)
          if request.method == "POST" and form.is_valid():
          message = form.cleaned_data['message']
          poster_name = form.cleaned_data['poster_name']
          article_id = id
          return HttpResponseRedirect(reverse('view_article', kwargs='id': id))

          except Article.DoesNotExist:
          raise Http404

          return render( request, 'blog/view_article.html', locals())


          Also, you don't need to redirect to another view, to redirect back to the current view. You can simply just redirect back to the same view.






          share|improve this answer















          You're entering an infinite loop. You need to only validate the form on the post.



          def view_article(request, id):
          try:
          article =get_object_or_404(Article, id=id)
          comments = CommentArticle.objects.filter(article_id=id)
          form = CommentForm(request.POST or None, initial='article_id': id)
          url = "submit_comment/" + str(id)
          if request.method == "POST" and form.is_valid():
          message = form.cleaned_data['message']
          poster_name = form.cleaned_data['poster_name']
          article_id = id
          return HttpResponseRedirect(reverse('view_article', kwargs='id': id))

          except Article.DoesNotExist:
          raise Http404

          return render( request, 'blog/view_article.html', locals())


          Also, you don't need to redirect to another view, to redirect back to the current view. You can simply just redirect back to the same view.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 1:34

























          answered Mar 22 at 1:24









          schillingtschillingt

          6,02511824




          6,02511824












          • Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

            – Theau Poulat
            Mar 22 at 15:35












          • You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

            – schillingt
            Mar 22 at 16:13

















          • Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

            – Theau Poulat
            Mar 22 at 15:35












          • You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

            – schillingt
            Mar 22 at 16:13
















          Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

          – Theau Poulat
          Mar 22 at 15:35






          Then the action parameter of the form in my template should be : <form action="% url 'view_article' %/ id " method="post"> but it doesn't seem to find the reverse.

          – Theau Poulat
          Mar 22 at 15:35














          You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

          – schillingt
          Mar 22 at 16:13





          You have a bug in your urls.py definition. You need to include the argument in the url. You'll find examples in the docs: docs.djangoproject.com/en/2.1/topics/http/urls

          – schillingt
          Mar 22 at 16:13



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291489%2fcant-refresh-the-page-after-form-submission%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript