I’m just curious if I’m doing this right.
I’m coding a private section of a website and wrote a login view which throws up a login window. I want to reuse this view for several urls which all go to a different views once access is granted. It doesn’t appear that you can pass arguments in the statements in urls.py, so I gave the login view an extra argument redirect
def login(request, redirect):
code to read the login form and parse the POST input
if POST and loginSuccessful:
return redirect(request)
else:
return render_to_response('login.html', context)
…and made specific urls each activate a different one-liner such as login_to_admin which simply returns the login view with a redirect argument.
def login_to_admin(request):
return login(request, admin)
def login_to_beta(beta):
return login(request, beta)
Everything works, I’m just wondering if this is the proper way to do this.
You can, actually.
The third item in the url conf can be a dictionary of kwargs which will be passed your view function.