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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현