Django signer value

2.1k Views Asked by At

Im trying to encrypt a django model pk to send it via url from a template using django signer :

signer = Signer()
value = signer.sign(pk)
url = {% myapp:url value %}

But i get in my url the pk plus the signature, like this example (pk=110) :

'110:EkfQJafvGyiofrdGnuthdxImIJw'

What i want it's only to retrieve the signature without the pk (110 or any value i send).

Any idea how ?, or any other way to encrypt the pk without using anothe field in the model ??

Thanks in advance

2

There are 2 best solutions below

0
On BEST ANSWER

Try first with a django filter for pk's signature and read the urls documentation for passing the pk and signature to the view

https://docs.djangoproject.com/en/1.11/topics/http/urls/#including-other-urlconfs

1
On

try this for signing:

from django.core import signing 

signed_value = signing.dumps('mytest')

and this for unsigning:

from django.core import signing 

unsigned_value = signing.loads(signed_value)

Regards