w11

适应国情

首先,因为我用了flask-bootstrap,结果每次调用的都是twtter的cdn,十分缓慢,我要想办法把它换成国内cdn,找到了这篇Use other CDN networks with Flask-Bootstrap

先要找到我的site-packages路径,最后在倒数第二个找到

>>> import sys
>>> print sys.path
['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']

按照Use other CDN networks with Flask-Bootstrap修改它:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flaskbootstrap/_init.py

加密解密

我需要办法实现对遗书内容的加密,目前找到的貌似比较合适的是AES加密,我需要先安装pycrypto模块

pip install  pycrypto

按照示例测了下,反正自己是看不懂了:

>>> from Crypto.Cipher import AES
>>> obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
>>> message = "The answer is no"
>>> ciphertext = obj.encrypt(message)
>>> ciphertext
'\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'

貌似这个加密的字符串要前后都有,我打算使用用户名加密试后不行,貌似只能支持16位,所以我换成了别的:

>>> len('This is a key123')
16
>>> len('a hardgress code')
16
>>> len('an other aescode')
16

最后搞来搞去发现只能加密16位倍数的,并且加密中文时候有问题,所以暂时先用最简单的base64

import base64

s1 = base64.encodestring('hello world')
s2 = base64.decodestring(s1)
print s1,s2

遗嘱页面

遗嘱页面把我折腾的不轻,耗了整整7个小时在上面,先是无法设置simeditor的默认值,后来找到官网issues解决了,后来里面的值在表单刷新后无法保持原先的内容,于是我又在js里面耗费了半天,本来是像直接把jinja里面的函数直接传入,结果js中字符的处理成了难题;后来在html中把值带了进去后,在刷新提交页面后,难以保持数据的一致性,剖开console里面调试了很久才终于成功,这里发现js是弱势,要补齐。

心跳页面