Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

803
Views
¿Cómo cifrar pk desde django url sin usar ningún paquete?

cómo cifrar y descifrar pk desde django url sin usar ningún paquete básicamente tengo una url como

 example.com/update/1

donde pk=1

quiero cifrar el pk como pk 1 = 345345435cgsfd2asdfaas

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Creo que no existe un método inbuld para hacer esto, pero al usar TimestampSigner , puede hacer lo siguiente:

Usando TimestampSigner, puede cifrar su PK y luego descifrar cuando desee la cadena original.

 >>> from datetime import timedelta >>> from django.core.signing import TimestampSigner >>> signer = TimestampSigner() >>> value = signer.sign(str(pk)) # encrypt the PK. >>> value '1:1NMg5H:oPVuCqlJWmChm1rA2lyTUtelC-c' >>> value = value.replace(pk,"") # doing this because, it append the original primary key + encrypted string. >>> value # use this PK to show in the URL. '1NMg5H:oPVuCqlJWmChm1rA2lyTUtelC-c' >>> repack = "{}:{}".format(pk,value) # When you want back the original PK, add the PK + encrypted string. >>>repack '1:1NMg5H:oPVuCqlJWmChm1rA2lyTUtelC-c' >>> signer.unsign(repack) # decrypt the PK. '1'

Espero que esto sea útil para usted.

over 4 years ago · Santiago Trujillo Report

0

Si no desea exponer pk a la URL, puede usar la firma. signing.dumps mientras cifra y firma. signing.loads en el descifrado. El objeto serializado se firma mediante TimestampSigner.

 >>> from django.core import signing >>> value = signing.dumps({"pk": "25"}) >>> value 'eyJwayI6IjI1In0:1g9Q4d:RJRYtpklLqaa3ey9c4d4sI0DKMc' >>> signing.loads(value) {'pk': '25'} >>> signing.loads(value,max_age=10) Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/avinash/.virtualenvs/mapd/lib/python3.6/site-packages/django/core/signing.py", line 140, in loads base64d = force_bytes(TimestampSigner(key, salt=salt).unsign(s, max_age=max_age)) File "/home/avinash/.virtualenvs/mapd/lib/python3.6/site-packages/django/core/signing.py", line 209, in unsign 'Signature age %s > %s seconds' % (age, max_age)) django.core.signing.SignatureExpired: Signature age 25.847949981689453 > 10 seconds >>>
over 4 years ago · Santiago Trujillo Report

0

$(function() { // Replace each URL $(".exampleclass").each(function(index) { // Get current URL var url = $(this).attr('href'); // Encode URL var encodedUrl = encodeURIComponent(url); // Replace $(this).attr("href", encodedUrl); }); });

Esta es la URL original:

 http://10.91.161.54:8181/validate_/listActivi/314/

Esta es la URL con reemplazo:

 http://10.91.161.54:8181/validate_/%2Fvalidate_%2FlistActivi%2F314%2F%20
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!