def login(request):
if request.method == 'GET':
form = LoginForm()
return render_to_response('login.html',RequestContext(request,{'form': form,}))
else:
form = LoginForm(request.POST)
if form.is_valid():
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username = username, password = password)
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
auth.login(request, user)
# Redirect to a success page.
#return render_to_response('equipmentdemo1.html',RequestContext(request))
return HttpResponseRedirect(reverse('equipmentapp.views.reporttable',kwargs={}))
else:
return render_to_response('login.html',RequestContext(request,{'form':form,}))
else:
# Show an error page
return render_to_response('login.html',RequestContext(request,{'form':form,}))
以上是我的登录函数,equipmentapp.views.reporttable是登录后的目标网页的视图函数。代码如下:
@login_required
def reporttable(request):
report_table = RepairReport.objects.all()
return render_to_response('reporttable.html', RequestContext(request, {'report_table': report_table, }))
我的想法是:reporttable对应的网页只有通过登录界面的认证,才能访问,不然,即使你输入目标网页的网址,也没有用。 但现在的 问题是,使用了login_required后,没有达到效果。请问问题在哪?