Home > OS >  Django - giving an unique ID to a blog post/element so it could be used with http referer
Django - giving an unique ID to a blog post/element so it could be used with http referer

Time:12-10

I am currently creating my first project and I am using an HTML template that I found online. It is a social media application where you should be able to upload a photo, like the photo, leave a comment, etc.

The issue is that I implemented all those functions, but liking, commenting, copying the URL (share buttong) refreshes the whole page and you end up at the very beginning of the page, because I am not sure how to refer the user to the post they liked/commented.

I am using

return redirect(f'{request.META["HTTP_REFERER"]}#{photo_id}')

, but since my posts don't have an unique identifier, it does nothing.

Any tips would be greatly appreciated. Thanks in advance!

CodePudding user response:

I added id="" to one of the divs used to construct the post and now it works.

CodePudding user response:

It's so bad that the post doesn't have a unique identifier but you can use other fields to do it without an id field.

you can use some fields like DateTime and title and author name for making a hash and use it instead of an id field.

  • Related