-1

I am a beginner in Django and I have been trying to make a social media app where a Post gets a like or a from any other user . Each time when a user adds a comment or likes a post I used forms to change the data in the database. I want the page to reload the fresh data i.e a comment or a like on the post but due to the redirect function the whole page is reloading interrupting my user experience .

In simpler terms there are 2 users x and y . y made a 1000 posts and all the posts are available on the profile page of y . x is critic and y asks x to comment the quality of the post for each and every one of the 1000 posts. According to what I wrote in views.py whenever x comments on a post I made a form that takes the content and stores it to the database but because of the redirect after each time he adds a comment on a post the web page is refreshed to the top of the page making x to scroll down all the posts to comment on a new post which makes the process irritating So how should I change my code so that the page is refreshed but x need not scroll down through all the posts to make a new comment and can also view the changes to the website dynamically **I sincerely apologise if i couldn't explain my question perfectly I can't post the code here due to professional reasons **

  • You should look into using JavaScript to submit comments using AJAX. This way comments can be submitted asynchronously without reloading the page – Iain Shelvington Aug 01 '20 at 23:39

1 Answers1

0

If I understand correctly, you are trying to get the form to submit without the whole page refreshing. Since you haven't posted code, it is hard to understand what exactly you want, but I will try to answer as best as possible.

This is possible with client-side JavaScript using JQuery AJAX or a JavaScript XMLHttpRequest. Basically, once the submit button is clicked, client side JavaScript sends a "silent" request to the server.

This answer shows an example of a post request without refresh.

Maxim
  • 51
  • 3
  • 10