suppose that you have a webpage that uses the post and get method, and you wrote the following view to generate it:
def homepage(request):
if 'login' in request.POST:
# ......... code goes here, and you return an appropriate response
if 'register' in request.POST:
# ......... code goes here, and you return an appropriate response
# When no Post request, just render the page
return render_to_response('homepage.html')
Question:
Is it considered good programming practice to split the above view into three views: one for login, one for register and one that would render the page? Or is it OK to keep it as it is.
EDIT
in the case listed above, I am not checking if the server received a “GET”. But the idea is still the same 🙂
I think a better idea would be to have each of the two forms submit to a different URL. Then you can define views for, e.g.,
/login,/register, and/(the default homepage handler). Your views for/loginand/registercan useif request.method == 'POST', and then redirect to the homepage if they are called with a GET request.