0
我創建了一個需要訪問kwargs的方法外DeleteView,像這樣:在DeleteView通用視圖Accesing kwargs
class DeletePost(DeleteView):
"""
Delete a post. Post deletion is only reserved to space
administrators or site admins.
"""
context_object_name = "get_place"
success_url = '/spaces/' + kwargs['space_name']
def get_object(self):
return get_object_or_404(Post, pk=self.kwargs['post_id'])
但很顯然,參數和關鍵字參數不能在外面使用方法。我也嘗試在get方法內建立success_url,但django不認識它。我能做些什麼來獲得space_name
參數?我試圖避免重寫像dispatch()等視圖核心方法。
似乎我誤讀了文檔。謝謝! – 2011-06-13 14:46:22