我正在玩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