我有一個CBV調用一些模型的方法(其中的計算機上運行某些進程,並連接到其他網站檢索數據)Django如何獲取與發送的帖子中的數據get?
class Edit(View:
def get(self, request):
object = Model.objects.get()
object.foo()
return object
def post(self, request):
...how can I get the object here without looking it
up and calling the method again
我想在後方法再次獲得對象,但我不想再次調用它,因爲我不想再次運行該過程。有什麼方法可以獲得這些信息嗎?它是通過context
這取決於你在返回的對象是什麼類型的數據。如果數據是用戶特定的,那麼你可以使用會話https://docs.djangoproject.com/en/1.10/topics/http/sessions/,如果不是那麼你可以使用Django的緩存https://docs.djangoproject。 com/en/1.10/topics/cache/ – mastazi
你的意思是「我不想再次運行這個程序」?這兩種方法用於處理不同類型的請求 - 「get」只針對「GET」請求運行,「post」針對「POST」請求運行。 – solarissmoke