Django 自带的 admin 提供了方便,如果要重写该怎么实现?如下:
1. 如果想实现自定义 User,加一个 app,如名为 auth2。在此 app 中加 用户 Model:
class User(AbstractBaseUser, PermissionsMixin):
'''继承 AbstractBaseUser 和 PermissionsMixin 可以重用认证必需的属性和方法,也可以完全重写'''
username = models.CharField(u'User Name', max_length=30, unique=True)
mobile = models.CharField(u'Mobile', max_length=11, blank=True)
email = models.EmailField(u'Email address', blank=True)
is_staff = models.BooleanField(u'staff status', default=False)
is_active = models.BooleanField(u'active', default=True)
date_joined = models.DateTimeField(u'date joined', default=timezone.now) # 如果用 Django 自带的 UserManager(见下面代码) 则必须,否则可不用
USERNAME_FIELD = 'username' # 指定代表用户名的字段名
REQUIRED_FIELDS = ['email'] # 如果用 Django 自带的 UserManager 时必须,因为其创建超级用户时必须有 email,即在syncdb 创建时要求填写
objects = UserManager() # 用 Django 自带的 UserManager,如果定义的字段出入较大,当然需要自己实现
def get_full_name(self):
'''启用 Django 自带 Admin 时需实现,因为 Admin 显示用户名时需要'''
return self.username
def get_short_name(self):
'''启用 Django 自带 Admin 时需实现,因为 Admin 显示用户名时需要'''
return self.username
然后在 INSTALLED_APPS 加上 auth2,并在 settings 添加配置 AUTH_USER_MODEL
AUTH_USER_MODEL = 'auth2.User'
如果想先确认是否成功,可以 syncdb 数据库会有 auth2_user 表,让项目跑起来之后走 Admin 认证。
2. 如果想进一步定义认证机制,比如不只校验用户名密码,可以自己实现 Authentication backend,官方参考:https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#writing-an-authentication-backend
3. 如果登录提交的表单不只用户名密码,自然需要重写 login 和 logout
@csrf_protect
@never_cache
def login(request, authentication_form=AuthenticationForm): # 认证表单 AuthenticationForm 需自己实现,可参考默认认证的表单
redirect_to = request.POST.get(REDIRECT_FIELD_NAME,
request.GET.get(REDIRECT_FIELD_NAME, '')) # 取 next 的值作为跳转页 URL
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL) # 需在 settings 设置登录后默认跳转页
if request.method == 'GET' and request.user.is_active and request.user.is_staff: # 已登录用户跳转
return HttpResponseRedirect(redirect_to)
if request.method == "POST":
form = authentication_form(request, data=request.POST)
if form.is_valid():
auth_login(request, form.get_user())
return HttpResponseRedirect(redirect_to) # 登录成功跳转
else:
form = authentication_form(request)
context = {
'form': form,
REDIRECT_FIELD_NAME: redirect_to,
}
return TemplateResponse(request, 'auth2/login.html', context)
def logout(request):
auth_logout(request)
return HttpResponseRedirect(resolve_url('/auth2/login/'))
以上只是最简单的重写认证需要做的。既然重写,为什么这么麻烦,还需沿用部分 Django 自带功能呢?至少以上的实现可以使用 Django 原有的用户权限模块的功能,尽量不重复造轮子。
Pingback: juegos de friv
Pingback: mondo sonoro
Pingback: orospu cocuklari
Pingback: bet
Pingback: cpns 2018 sma kejaksaan agung
Pingback: how to make money with a iphone
Pingback: Bdsm chat
Pingback: iraqi Engineer
Pingback: penerimaan cpns kejaksaan 2018
Pingback: cro gvk bio
Pingback: wedding planner services in hyderabad
Pingback: Software klinik
Pingback: real estate agents
Pingback: horoscope
Pingback: PK Studies CRO
Pingback: Dokter kebidanan dan kandungan banten
Pingback: guaranteedppc.com
Pingback: Continue Reading
Pingback: Tree of Innovation SEO
Pingback: inpo cpns
Pingback: 家
Pingback: 루비게임 엘리트게임 루비게임주소
Pingback: Corporate Reputation Management solutions
Pingback: détails
Pingback: hoverboard
Pingback: Replica Watches
Pingback: jhfn e
Pingback: C++ Tutorial
Pingback: best audiobooks on scribd
Pingback: Caco-2 cell model
Pingback: Elizabeth Bay Locksmith
Pingback: horoscope rat 2018
Pingback: Online Casino Reviews
Pingback: hgh steroid for sale
Pingback: in vitro protein binding studies
Pingback: best steroid store
Pingback: online casino bitcoin
Pingback: top 10 kiwi casinos
Pingback: Moving To France
Pingback: fuck islam
Pingback: http://fitandwellosteo.com.au/
Pingback: Best online casino reviews in New Zealand
Pingback: Free UK Chat
Pingback: sherman
Pingback: website design bengaluru
Pingback: PK screening
Pingback: turinabolas
Pingback: billiga fotbollströjor
Pingback: billiga fotbollströjor
Pingback: billiga fotbollströjor
Pingback: Branding
Pingback: Fodboldtrøjer
Pingback: fotbollströjor barn
Pingback: fotballdrakter
Pingback: website
Pingback: Runescape gold
Pingback: psg fodboldtrøje
Pingback: liverpool tröja
Pingback: maglie a poco prezzo online
Pingback: free bitcoin cash
Pingback: maglie calcio a poco prezzo
Pingback: fußballtrikots kaufen
Pingback: maglie calcio
Pingback: fodboldtrøjer
Pingback: hanky panky vixen bralette in black
Pingback: nike new wmns nike lunartempo 2 818098 racer bluewhite womens 11
Pingback: vans marvel buy vans marvel online in india
Pingback: kit infant 1陋 equipaci贸n 2018 19
Pingback: haute hippie gold sparkle sweater sz xs s
Pingback: good night tshirt shirt tees adult unisex custom clothing
Pingback: shop vintage shop vintage chanel pre owned handbags
Pingback: mens nike air max 270 black white anthracite ah8050 002 huarache
Pingback: miu miu sunglasses clear new zealand
Pingback: leather low top sneakers converse chuck taylor all star
Pingback: Karl Lagerfeld CAMISA CASUAL - ROSA 100% seda Corte recto & fluido Ocasión : lifestyle business 2482973
Pingback: bolso herschel supply bamfield fall floral
Pingback: ltimo minuto hombre columbia peakbagger gafas de sol 002 matte black smoke tienda de
Pingback: nike air vapormax 2019 cushioning casual sports shoes black blue 849558 012
Pingback: tenis nike air max 270 masculino cinza
Pingback: men summer stripe flip flops shoes sandals casual male slipper flip flop strap flip flops intl philippines
Pingback: kate middleton est adepte des robes blanches puretrend
Pingback: yeezy boost 350 zebra medusa hoodie to match yeezy 350 boost zebra sneakers
Pingback: 2019 mens bodysuit spandex online store. best mens bodysuit spandex
Pingback: footlocker vapormax utility
Pingback: magnolia mill snow bunny beanie
Pingback: the italian job brooks brothers new era
Pingback: womens sandals topshop limbo snake effect platform sandals black
Pingback: t锚nis pro keds royal hi core azul marinho pk101003 t锚nis casual no
Pingback: m jordan shoes dress shoe lacing
Pingback: aviator sunglasses 58mm gold 23k
Pingback: 贸culos de sol italiano. carregando zoom
Pingback: france hommes converse chuck taylor ox hommes chaussures taille neon orange automne
Pingback: discount nike pg 2 pure platinum neo turquoise
Pingback: nike white label aw77 tf fz 1mm camo jacket light blue lacquer
Pingback: bonnie jean plaid dress toddler girls belk kids patterns
Pingback: joe montana mitchell ness jersey for sale in charlotte
Pingback: mocassim dedmar couro branco franja
Pingback: off shoulder dress for sale pink
Pingback: ladies red stockings
Pingback: adidas originals joggingbroek zwart wit
Pingback: goedkoop gucci 2018ss ace sneaker schoenen myluxshop offici毛le website
Pingback: tommy jeans mens original end on end long sleeve classic casual
Pingback: father and son anthony reading holds his newborn son joey. the father was expecting
Pingback: tatler magazine the freebie sunglasses
Pingback: baby quilted chambray bear one piece
Pingback: nike mercurial superfly v fg flyknit mens football shoes pink purple
Pingback: billybandit boys yellow polo shirt
Pingback: online store icon free icons library
Pingback: top di moda puma scarpe italia blu scarpe da ginnastica uomo italia vendita calda r698 ingrandisci
Pingback: balenciaga mini city vs part time youtube
Pingback: 噩賵賾賷 on twitter 丕胤賱亘 卮乇賷丨丞 噩賵賾賷 丕賱丌賳 賵丕丨氐賱 毓賱賶 100 乇賷丕賱 乇氐賷丿 兀爻丕爻賷
Pingback: neosport womens water shoes swimming equipment and gear
Pingback: trina turk jakarta embroidery high neck one piece swimsuit indigo blue size 10
Pingback: funda carcasa para iphone 5 5s rosa arbol corazones con brillantes
Pingback: dive in thong back bodysuit neon yellow style delivers
Pingback: brooks brothers mens daisy swim trunks
Pingback: farming simulator farming simulator 15 logo t shirt
Pingback: spice up your life tshirt
Pingback: funny tshirt sites
Pingback: colin kaepernick icon jersey offers nba stars another way to show solidarity
Pingback: crocodile embossed elevator dress boots men taller 6.5cm
Pingback: 蟿蟽 谓蟿蔚 2016 慰 伪蟺 位蠀蟿慰 慰未畏纬 纬喂伪 蟿喂 蟺喂慰 stylish 渭伪 蟻蔚 蟿蟽 谓蟿蔚
Pingback: d谩mske 膷lenkov茅 膷i啪my lb 1106 khaki
Pingback: levis jeans online buy at cheap us prices
Pingback: bracciale elegante donna moda palline sfere cuore charm ciondolo moda argento
Pingback: 鏈棩銇偦銉笺儷鎯呭牨 amazon銈裤偆銉犮偦銉笺儷銇?0 浠ヤ笂銈儠銈?vinmori 銈广兗銉勩儥銈广儓
Pingback: sexy handschuhe schn眉ren lange fischnetz finger handschuhe goth kost眉m ellenbogen l盲nge frauen dame 025
Pingback: 纬蠀谓伪喂魏蔚委伪 蟺位蔚魏蟿维 蟺蟻慰蟽蠁慰蟻苇蟼 ale
Pingback: cck lux p枚tty枚s push up bikini
Pingback: fantasia infantil hippie masculino cacau center
Pingback: 2018 new children girls summer shoes kids sandals for girls genuine flowers princess shoes girls sandals
Pingback: f茅rfi f眉rd艖 short geographical norway quafto men white
Pingback: hunkem枚ller lounge badeanzug damen lila bekleidung bademode badeanz眉ge outlet online bestellen
Pingback: movies
Pingback: movies online
Pingback: karan johar
Pingback: Top Movies
Pingback: Movies1
Pingback: 11 10 2019
Pingback: confortable nouvelle collection bottines nike air max 1 mid
Pingback: garantie 100 vente en ligne de puma pour puma souliers chaussures puma femme puma french
Pingback: smotretonline2015.ru
Pingback: Serial smotret
Pingback: kinokrad
Pingback: kinokrad 2020
Pingback: ñïèñîê íîâûõ ôèëüìîâ
Pingback: nemidor women vintage short sleeve casual print a line summer dress v neck belted plus size party midi swing dress in dresses from womens
Pingback: Watch Tv Series Online
Pingback: casino
Pingback: Kinokrad 2019 Kinokrad Hd
Pingback: filmy-kinokrad
Pingback: kinokrad-2019
Pingback: filmy-2019-kinokrad
Pingback: serial
Pingback: ladies air hostess flight attendant stewardess fancy dress costume airline hat
Pingback: zara mujer rebajas abrigos
Pingback: pure high top grey black red
Pingback: cerialest.ru
Pingback: vintage louis vuitton wallet. super cute
Pingback: youtube2019.ru
Pingback: target maternity jeans for sale ebay
Pingback: dorama hdrezka
Pingback: movies hdrezka
Pingback: HDrezka
Pingback: kinosmotretonline
Pingback: LostFilm HD 720
Pingback: 2015 latest ladies sandals designs shoes cut outs breathable
Pingback: 2016 lego frozen sets photos arendelle castle sleigh
Pingback: tv reklam webb tv r氓dgivning mediabyr氓n i norr
Pingback: oboz bridger low light trail shoes mens my shoes best
Pingback: converse adult converse chuck taylor all star sneakers
Pingback: sllaiss amore infinito infinito collana bavaglino per le donna ragazze ciondolo infinity
Pingback: acg boots size 4
Pingback: cheap new york giants jersey wholesale new york giants
Pingback: trustedmdstorefy.com
Pingback: herren lacoste t shirts poloshirts t shirt print flamant blanc
Pingback: festdrakt str 86
Pingback: standard double cell room darkening shades
Pingback: tie najlep拧ie p谩nske top谩nky na zimu blog fashionspy.sk
Pingback: bofilm ñåðèàë
Pingback: bofilm
Pingback: 1 seriya
Pingback: mini robe chic pour soir茅e cocktail v锚tements pas cher mode f茅minine sexy
Pingback: computer reading glasses blue light
Pingback: Êîíñóëüòàöèÿ ïñèõîëîãà
Pingback: what makes an herm猫s himalayan crocodile birkin so special
Pingback: topedstoreusa.com
Pingback: pirates of the caribbean costumes on sale the costume rag
Pingback: bir bir iflas 艧imdi de atalar giyim haberler
Pingback: hqcialismht.com
Pingback: viagramdtrustser.com
Pingback: 诪诇讜谉 hotel 讘拽讜住讟讛 讚诇 住讜诇 讙讜诇讬讘专
Pingback: black clover navy white red ole miss 2 tone vintage snapback hat
Pingback: 薪邪斜芯褉 褝褋锌邪薪写械褉芯胁 mini bands 25 5 褋屑
Pingback: 10k white gold princess cut center diamond engagement ring
Pingback: buty trekkingowe m臋skie grafit r. 43
Pingback: pantaloni sexy sport pantaloni pantaloni dama
Pingback: 斜芯褋芯薪芯卸泻懈 卸械薪褋泻懈械 seastar 40 red
Pingback: balenciaga rood sneakers
Pingback: nieuwe mode kids kleding meisjes zomer set zwart kant strapless blouse witte rozen gaten denim shorts kinderen meisjes kleding in
Pingback: little star organic white long sleeve bodysuits 4pk
Pingback: miso lola child girls boots
Pingback: 4serial.com
Pingback: See-Season-1
Pingback: Evil-Season-1
Pingback: Evil-Season-2
Pingback: Evil-Season-3
Pingback: Evil-Season-4
Pingback: Dollface-Season-1
Pingback: Queer-Eye-We-re-in-Japan-Season-1
Pingback: erikoistuminen tanskan tapaan nly
Pingback: nileriver
Pingback: k酶b oball rollin rainstick rangle jollyroom
Pingback: v谩lenky s ko啪u拧inkou 拧ed茅
Pingback: cupooftea
Pingback: serial 2020
Pingback: Dailymotion
Pingback: Watch+movies+2020
Pingback: vn wrap brun l盲der vinyl
Pingback: s.oliver gutscheine nov. 2019 10 50 rabatt einl枚sen
Pingback: ta拧ka adidas performance w 3s tr tote r暖啪ov谩 kvalitn茅 拧portov茅 kabelky
Pingback: serial-video-film-online
Pingback: moncler mujeres chaquetas bicolor puffer abajo chaquetas
Pingback: tvrv.ru
Pingback: 1plus1serial.site
Pingback: #1plus1
Pingback: 1plus1
Pingback: 2020
Pingback: orangewood suites university in austin tx
Pingback: 褋械褉械卸泻懈 写谢褟 写褨胁褔邪褌芯泻 写懈褌褟褔褨 褋械褉械卸泻懈 写谢褟 写褨胁褔邪褌芯泻 褑褨薪邪
Pingback: visoke 膷izme za bedra su 2850 crna
Pingback: mens texas rangers customized 2014 gray jersey on sale for
Pingback: den lille eksklusive
Pingback: nike air max 91 nejvet拧铆 obchod s tenisky a kab谩ty
Pingback: Watch Movies Online
Pingback: Film
Pingback: Film 2020
Pingback: Film 2021
Pingback: watch online TV LIVE 2020
Pingback: birkenstock hvide sandaler 1005280 mayari birko flor white
Pingback: online nakupov谩n铆 bugatti p谩nsk茅 kabelky cognac
Pingback: counter 盲kta adidas obyo js adilette jeremy scott skor m盲n
Pingback: kleding vrouw kuitbroek fit 500 regular fit pilates en lichte gym dames zwart
Pingback: joules ladies fabulously fluffy socks henmores
Pingback: nike janoski black white gum
Pingback: new winter fashion justin bieber sweatshirts men
Pingback: fake lab t shirt uomo play comme de gucci taglia small s
Pingback: p谩nsk茅 tri膷ko nike training swoosh b铆l茅
Pingback: human design
Pingback: dizajn cheloveka
Pingback: case logic universele foliocover surefit 8 inch zwart
Pingback: womens military fleece
Pingback: christian louboutin mi note 5 pouch
Pingback: tenisice adidas Pure Boost hr
Pingback: 绉嬪啲銈儠銈c偣銈炽兗銉?銈儠銈c偣銈偢銉ャ偄銉?銈广兗銉勩偝銉笺儑
Pingback: body kouros yves saint laurent eau de toilette
Pingback: magazine mode enfant
Pingback: womens jordan retro 3 black cat
Pingback: lacoste pullover a girocollo in cotone a righe sfalsate uomo pull methylene flour graphite
Pingback: msch femme mohair pullover green
Pingback: adidas samba all colors
Pingback: online shopping herr tommy hilfiger
Pingback: puma oracle racing sailing womens boots sport shirt 06
Pingback: find the best savings on womens givenchy 55mm special fit
Pingback: 泻褍锌懈褌褜 锌谢邪褌褜械 薪懈卸械 泻芯谢械薪邪 胁 懈薪褌械褉薪械褌 屑邪谐邪蟹懈薪械 褑械薪邪
Pingback: nib christian louboutin bordeaux sneaker nib christian
Pingback: nike academy football black backpack new 2018 2019 work school great
Pingback: al futuro la 4 blu ray unico
Pingback: flora snake silk pajama pant multicolor
Pingback: hodiny 拧tvorcov茅 hned茅 neoby膷ajn媒 dar膷ek pre babi膷ku z vlastnej grafiky
Pingback: buy free shipping bracelet doggy and get free shipping on
Pingback: viagra
Pingback: viagra online
Pingback: mitre impel max football unisex sport activity
Pingback: cherkassy film
Pingback: ¯jak Son³k 2020
Pingback: pharmacy
Pingback: cialis
Pingback: generic viagra
Pingback: smotret onlajn besplatno v kachestve hd 1080
Pingback: movies-unhinged-film
Pingback: malenkie-zhenshhiny-2020
Pingback: dom 2
Pingback: zoom-psykholog
Pingback: zoom-viber-skype
Pingback: Vratar Galaktiki Film, 2020
Pingback: Vratar
Pingback: Cherkassy 2020
Pingback: chernobyl-hbo-2019-1-sezon
Pingback: moskva-psiholog
Pingback: batmanapollo.ru
Pingback: 323
Pingback: 525
Pingback: dom2-ru
Pingback: Tenet Online
Pingback: psy psy psy psy
Pingback: krsmi.ru
Pingback: like-v.ru
Pingback: CFOSPUK
Pingback: MAMprEj
Pingback: fgu0ygW
Pingback: bitly.com
Pingback: akmeologiya
Pingback: dizain cheloveka
Pingback: human-design-hd
Pingback: batmanapollo
Pingback: tsoy
Pingback: 44548
Pingback: 44549
Pingback: hod-korolevy-2020
Pingback: HD
Pingback: 158444
Pingback: groznyy-serial-2020
Pingback: 38QvPmk
Pingback: bitly.com/doctor-strange-hd
Pingback: bitly.com/eternals-online
Pingback: bitly.com/maior-grom
Pingback: matrica-film
Pingback: dzhonuikfilm4
Pingback: bitly.com/batman20212022
Pingback: bitly.com/venom-2-smotret-onlajn
Pingback: bitly.com/nevremyaumirat
Pingback: bitly.com/kingsmankingsman
Pingback: bitly.com/3zaklyatie3
Pingback: bitly.com/1dreykfilm
Pingback: bitly.com/topgunmavericktopgun
Pingback: bitly.com/flash2022
Pingback: bitly.com/fantasticheskietvari3
Pingback: bitly.com/wonderwoman1984hd
Pingback: 1444
Pingback: cleantalkorg2.ru
Pingback: 232dfsad
Pingback: cleantalkorg2.ru/sitemap.xml
Pingback: join vk
Pingback: vk login
Pingback: svaty7sezon
Pingback: svaty 7 sezon
Pingback: svaty 7