luffy專案中關於APIView的使用

2022-03-16 12:22:48 字數 2136 閱讀 7812

views中

"""購物車的新增課程請求

:param request:

:return:

""".....

defget(self,request):

"""檢視購物車列表請求

:param request:

:return:

"""pass

from rest_framework.authentication import

baseauthentication

from rest_framework.exceptions import

authenticationfailed

from api.models import

usertoken

class

loginauth(baseauthentication):

defauthenticate(self, request): #一定要重寫該方法

token=request.get.get("

token")

token_obj=usertoken.objects.filter(token=token).first()

iftoken_obj:

return

token_obj.user,token_obj.token

else

:

raise

authenticationfailed("

認證失敗了

")

自定義異常處理  from api.utils.exceptions import priceexception
class

priceexception(exception):

def__init__

(self):

self.msg="

**策略有問題,你不是人!

"

自定義 response      from api.utils.response importbaseresponse
class

baseresponse(object):

def__init__

(self):

self.data=none

self.error_msg=""

self.code=1000@property

defdict(self):

return self.__dict__

luffy專案相關

pip install django redis 在settings中配置 redis快取配置,以後所有的快取都在redis中 caches decode responses true password pip install django cors headers 在settings中配置 註冊 ...

專案中 關於AlertDialog的顯示

因為很多頁面要用到這個打 的dialog,所以做成乙個utils,直接呼叫。public static void showfindaitdialog final context context yesbutton.setonclicklistener new onclicklistener log ...

關於cachedrowset在實際專案中的應用

由於專案需求原因,需要實現乙個功能就是,抽取大量的資料庫資料然後寫入文字並打包上傳。看似乙個很簡單的東西,在大資料量的環境下就顯得不是那麼簡單了。首先有60張左右的表需要進行資料的處理。各個公司情況不同,表的總資料量可能是幾千萬到幾十億不等。所以,耗時非常嚴重。由於只是單純的進行資料的提取加工寫入文...