day 65 auth module, function pluggable design, bbs table design

auth module
with auth module, use a full, do not write their own part, with a part of someone else

# Create a Super Admin user to log in django admin of

createsuperuser # verify whether the user is present user_obj = auth.authenticate (username = username, password = password) # returns the data object is no return None



# Save the user login status
auth.login (request, user_obj) # After executing the sentence as long as the place can get a request, can obtain the current logged-on user objects through request.user

# Determine whether the current user is logged
request.user.is_authenticated ()

# Get the current user data object
request.user

 

# View itself plus parity checks whether the user login
from django.contrib.auth.decorators Import login_required
# @login_required (LOGIN_URL = '/ XXX /') # local configuration
@login_required # global configuration
def home (request):
  return HttpResponse ( 'home page')


# Jump when the user is not logged in a case where there are two configurations url
1. Local parameters within specified by login_url decorator bracket
2. Under the global configuration of all the user is not logged on to jump to a unified view url
profile in
LOGIN_URL = '/ login /'

# Change Password check the original password is correct is_right = request.user.check_password (old_password) set a new password request.user.set_password (new_password) request.user.save () # user registration from django.contrib.auth.models import User User.objects.create (username = username, password = password) # do not create a password will be saved directly into plaintext using User.objects.create_user (username = username, password = password) # create a regular user User.objects.create_superuser (username = username, password = password, email = '123 @ qq.com') # create a super user mailboxes field must fill in the fields # expansion auth_user table first (not used) using the one-relationship table extension field second ( Inheritance) 1. dictation to write a class that inherits the original auth_user class and then tell django settings in the configuration file to use your new class as an alternative auth_user table from django.db import models






















from django.contrib.auth.models import AbstractUser
# Create your models here.

class Userinfo (AbstractUser):
Note: You inherited a custom table after AbstractUser, the field can not conflict with existing
  Phone = models.BigIntegerField ()
  Avatar = models.FileField ()
  register_time = models.DateField (auto_now_add = True)


2. Be sure to specify the settings configuration file
AUTH_USER_MODEL = 'app01.Userinfo'
# fixed syntax: AUTH_USER_MODEL = '. Application Name Table'

inheritance by way of the above table can continue to use all the functions auth module
Tips: When when you need some user-related functions may consider using auth module

 

 

Referring django middleware plug-in configured to implement the design features (*******)

By a string, and the classes into modules, so long as the string comment out, can prohibit the import modules and classes,

In the settings in the string writing.

 

BBS table design
# project development process 1. Demand analysis architects + + development team leader, product manager before going to talk about the needs of the client company, to advance this project should reckon how to do inside the pit which is relatively simple point to think ahead solutions have to guide customers in conscious when talking with customers towards you already want to put up a good program needs





2.项目设计
架构师干的活
项目的报价(每个程序员按照人头 每天2000+左右)
语言的选择
框架的选择
数据库的选择(主库用什么 缓存库)
功能划分
开发部开发组长开会分发任务

3.分组开发
架构师和开发组长将项目整体的框架搭建出来
然后让小组成员各自朝着各个部分填写代码即可

4.测试
1.自己写测试脚本

2.测试部分专门测试

5.交付上线
交给你们公司的运维人员或者是客户公司的运维人员


#表

 

Guess you like

Origin www.cnblogs.com/wwei4332/p/11772174.html