我正在玩django,並建立了一個小應用程序,用戶可以通過url http:///localhost:8000/username/info/訪問他們的信息。我想通過http:///localhost:8000/username/info/edit/添加編輯該信息的功能,但也希望確保當前登錄的用戶(使用django.contrib.auth)只能訪問他的信息。我做到了這一點通過以下操作視圖(在視圖ARGS用戶名是URL中捕獲):django - 限制用戶只編輯他們自己的信息
@login_required
def edit_info(request, username=''):
if request.user.username == username:
# allow accessing and editing the info..
else:
# redirect to some error page
所以,很顯然,我不希望用戶「約翰尼」編輯的信息屬於用戶'jimmy'只需將他的瀏覽器指向/ jimmy/info/edit /。以上的作品,但我擔心的是,在安全方面,我錯過了一些東西。這是否正確? 謝謝。
我會在你的'else'塊,錯誤代碼403響應的粉絲。 – 2009-10-22 10:11:59