PHPz2017-04-17 17:58:32
If you want to serialize json, you can use marshmallow
With SALAlchemy, it is marshmallow-sqlalchemy
PHPz2017-04-17 17:58:32
We use pickle for serialization when using sqlalchemy. When the front end passes it back directly, we can directly obtain the object without having to go to the database to obtain the object again. The code is as follows:
251
252 def __str__(self):
253 return base64.urlsafe_b64encode(pickle.dumps(self)) .decode('ascii')
254
255 @staticmethod
256 def fromstr(ss):
257 if isinstance(ss, bytes):
258 ss = ss.encode('ascii')
259 obj = pickle.loads(base64.urlsafe_b64decode(ss))
260 return obj