Creating POST context processor

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Creating POST context processor



I have a follow button that I'd like to have on some pages. This follow button follows the same logic on all pages. User clicks follow button -> user follows user -> user is redirected to the same page I have this logic on one page (ProfileView), but I'd like to extend it on other pages (Followers page, following page, etc)


User clicks follow button -> user follows user -> user is redirected to the same page



ProfileView in views.py


def post(self, request, slug):
follower = self.request.user

self.object = self.get_object()
follow_unfollow(follower, self.object.id) //Function that follows/unfollows

self.object = self.get_object()
context = self.get_context_data(object=self.object)
return render(request, self.template_name, context=context)



This works correctly. However, I'd like to make this post function outside of ProfileView and have it in something like a context processor. If the user is on another user's followers page and clicks the follow button there should be a post method that handles that request (This post method should be the same post method if we were on another page like the profile page.) Is there a way I can make my post method reusable that way I can handle the request from whatever page using 1 post method?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

React Native Navigation and navigating to another Screen problem