I am trying to find best solution for encrypting my URL, I have found some old versions, for python 2.2.
I need to set my URLs, not to display like this:
.com/AddPost/1
/ and .com/PostDetail/40
.
But something like this:.com/AddPost/DMQRzZWMDdGQtbndzBHNsawN0aXRsZQR0ZXN0AzcwMQR3b2UDMjQwMjEwNQ
That you can not guess what PK is and access that page:
URLs:
urlpatterns = [
path('PostDetail/<int:pk>', PostDetail.as_view(), name ='post_detail'), ]
view.py:
class PostDetail(DetailView):
model = Post
template_name = 'post_detail.html'
def get_context_data(self, *args,**kwargs):
post = Post.objects.all()
context = super(PostDetail,self).get_context_data(*args,**kwargs)
stuff = get_object_or_404(Post,id=self.kwargs['pk'])
total_likes=stuff.total_likes()
context['total_likes'] = total_likes
return context