Views - VamsiSangam/PhDPortal GitHub Wiki
This is the homepage for the documentation of the application views.
Generic view method template
@login_required # if login is required to access this view
def method_name(request):
"""
Method documentation string.
"""
if not validate_request(request): return redirect(reverse(URL_FORBIDDEN)) # mandatory, validates request
if request.method == "GET":
# does something if this method should do something for
# a GET request, otherwise this block won't be there
elif request.method == 'POST':
# does something if this method should do something for
# a POST request, otherwise this block won't be there
else:
# this ensures that user gets a 'Bad request' page
# when user requests in other than GET or POST methods
return redirect(reverse(URL_BAD_REQUEST))
The above template is the general template followed when writing a view method. Actual method implementations will look different but will have the above skeleton.
Common rules for all methods in view files
- One
- Two