开发者

Send encrypted parameters to a view in django

开发者 https://www.devze.com 2023-01-01 03:28 出处:网络
I want to send a project_id veriable in a edit_project view in django. Can any one tell me th开发者_运维问答at how can I do that?One thing about encryption is that if you encrypt the ID to pass it aro

I want to send a project_id veriable in a edit_project view in django. Can any one tell me th开发者_运维问答at how can I do that?


One thing about encryption is that if you encrypt the ID to pass it around, you'll also have to decrypt it before you can look it up.

An alternative that might work for you is to add a unique*, secure hash to every Project object, which is created on save() to a recipe of your choice: eg

import hashlib

class Foo(models.Model):
  ...attributes here, eg name, ...

  obj_hash = models.CharField(max_length=40, blank=True, null=False)

  def save(self):

  if not self.obj_hash:
    self.obj_hash = hashlib.sha1(string of attributes vals here).hexdigest()

  super(Foo, self).save()

and then in your urlConf and views have something that uses or looks up Foo by its obj_hash rather than its id.

(* Yes, I know it's not technically guaranteed to be unique, but hash clashes shouldn't be a problem. You can check if it exists before saving if you really want.)


but, if you need to encrypt data use Secure Socket Layer (SSL)

0

精彩评论

暂无评论...
验证码 换一张
取 消