django常用封装
#encoding:utf-8
from django.shortcuts import render_to_response
import hashlib
from binascii import b2a_hex
def GetData(request,key):
'''
获取GET与Post提交参数的值
:param request:
:param key:
:return:
'''
if request.method=="GET":
return request.GET.get(key,None)
return request.POST.get(key,None)
def Is_GET(request):
if request.method=="GET":
return True
return False
def Is_POST(request):
if request.method=="POST":
return True
return False
def Is_PUT(request):
if request.method=="PUT":
return True
return False
def Is_DELETE(request):
if request.method=="DELETE":
return True
return False
def IS_AJAX(request):
if request.is_ajax():
return True
return False
def check_isLogin(main_func):
'''
登录验证
:param main_func:
:return:
'''
def wrapper(request,*args,**kwargs):
if "user" not in request.session:
return render_to_response(urlconfig.login)
return main_func(request,*args,**kwargs)
return wrapper
def getMD5hashCode(pwd):
'''
md5加密
:param pwd:需要加蜜的密码明文
:return:返回加密后的密文
'''
m=hashlib.md5()
m.update(pwd)
return m.hexdigest()
def encodeBase64(passStr):
'''
base64编码
:param passStr:
:return:
'''
return base64.encodestring(passStr)
def decodeBase64(passStr):
'''
base64解码
:param passStr:
:return:
'''
return base64.decode(passStr)