Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Python Development Notes

Shulou Source: shulou.com Published: 2022-06-03 07:53:11 11月23日 Update

1. As_view method of django base class View # Import View base class from django.views.generic.base import View# import template rendering function from django.shortcuts import render# this is the authentication class class LoginView (View) for user login: "" login authentication "" # get way to obtain login page def get (self, request): return render (request, 'login.html', {}) # user submit form Return to the home page def post (self, request): "" submit form "" return render (request, 'index.html', {}) urls, import LoginView, and call the .as _ view method url (r' ^ login/$', LoginView.as_view (), name='login'). When the class view calls the as_view method, the request method at the time of the request will be automatically mapped to the corresponding class method. For example, the get method of request corresponds to the get method of class view. As_view can only automatically correspond to get and post (specific request methods have a list in class attributes: http_method_names = ['get',' post', 'put',' patch', 'delete',' head', 'options',' trace']). If I define my own methods in class view, as_view can't correspond to my custom methods.

Tags: Methods views users forms login authentication home page functions properties methods templates pages notes development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Huawei Linux MySQL