I'm developing a site with a login box on the base.html template page. For all the pages that require the user to be logged in, I'm using the login_required decorator. However, I'd like the user to be able to login on the other pages if they want to.
Among the things that the "login_required" decorator does is handle the nuts and bolts of logging in, in addition to verifying you're logged in before showing you the desired page.
What I'd like is a "login_optional" decorator (or optional parameter within login_required) for these optional pages. I can't find such a thing. Does it exist and I'm just missing it or do I need to roll my own login handling routine for these views?
Thanks
Mike
EDIT (sample code)
template
<form action="" method="post">
<label for="username">Username:</label>
<input type="text" name="username" value="" id="username" size="10"/>
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password" size="10"/>
<input type="submit" value="Login"/>
<input type="hidden" name="next" value="{{ next|escape }}"/>
</form
>
login required code
@login_required
def chooseDistributor(request):
user = request.user
# blah stuff deleted
# NOTHING TO HANDLE request.POST!
return render_to_response('choose_distributor.html',locals())
login optional code
def showWelcome(request):
user = request.user
return render_to_response('welcome/home.html',locals())