Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python Development Notes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report