hash - How to generate a hashed share link using flask -
i developing app, , want realize "share" function, can share content facebook or twitter. every content has own id, , want generate hashed link when "share" button clicked. say, if there essay a, , want share facebook, click "share facebook" button. should generate url, looks "http//my_app_backstage_server/essay/hash(id)", hash(id) not real id of content, hashed one. how can implement in flask framework? thanks!
facebook button or twitter create link page on facebook (if don't want generate special links actions). need provide content pages access.
you can generate random string or real hash , store on database (don't forget value must unique):
import random import string hashlib import sha512 simple_chars = string.ascii_letters + string.digits def get_random_string(length=24): return ''.join(random.choice(simple_chars) in xrange(length)) def get_random_hash(length=24): hash = sha512() hash.update(get_random_string()) return hash.hexdigest()[:length]
i think don't need have both id , hash access content.
if want generate links share button action (i realy can't understand why):
- you must add route links;
- you must add route create link;
- you can create link ajax , share after if don't have user permission share data;
- you can create link app (ajax or link) if have user permission share data.
Comments
Post a Comment