我正在使用此代码来验证我的views.py
.
@login_required
def my_view(request, username):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404(u'User not Found')
if user == request.user and request.user.is_authenticated():
variables = RequestContext(request, {})
return render_to_response('my_template.html', variables)
还有另一种方法(即更少的代码)来验证用户,还是我需要把它放在每个视图中?