基於django的登入註冊系統

2021-09-30 01:54:34 字數 3057 閱讀 8259

2.功能實現

3.小結

'請檢查填寫的內容'

if login_form.is_valid():

username = login_form.cleaned_data.get(

'username'

) password = login_form.cleaned_data.get(

'password'

)try

: user = models.user.objects.get(name=username)

except

: message =

'使用者不存在'

return render(request,

'login/login.html'

,locals()

)ifnot user.has_confirmed:

message =

'使用者還未經過郵件確認'

return render(request,

'login/login.html'

,locals()

)if user.password == hash_code(password)

: request.session[

'is_login']=

true

request.session[

'user_id'

]= user.

id request.session[

'user_name'

]= user.name

return redirect(

'/index/'

)else

: message =

'密碼不正確'

return render(request,

'login/login.html'

,locals()

)else

:return render(request,

'login/login.html'

,locals()

) login_form = form.userform(request.post)

return render(request,

'login/login.html'

,locals()

)

def

send_mail

(email,code)

:from django.core.mail import emailmultialternatives

subject =

'來自yzj的註冊確認郵件'

text_content =

''' 感謝註冊,這裡是yzj\

'''html_content =

''' 感謝註冊www.yzj.com,\

這裡是yzj

站點鏈結完成註冊確認!

此鏈結有效期為{}天!

'''.format

('127.0.0.1:8000'

, code, settings.confirm_days)

msg = emailmultialternatives(subject,text_content,settings.email_host_user,

[email]

) msg.attach_alternative(html_content,

'text/html'

) msg.send(

)# 郵箱配置

# settings.py

email_backend =

'django.core.mail.backends.smtp.emailbackend'

email_host =

'smtp.qq.com'

email_host_user =

'******@qq.com'

email_host_password =

'***x'

email_port =

25email_use_tls =

true

#確認天數

confirm_days =

7

from captcha.fields import captchafield

captcha = captchafield(label=

'驗證碼'

)

github原始碼.

參考文件:劉江的部落格教程.

django 登入 註冊

一 登入 目錄結構如下 2 在主專案urls.py中新建users的include url 4 登入利用django渲染好的模板,url定義如下 login.html檔案如下 二 退出 1 退出用django的logout模組,同樣,先定義url 2 定義好之後,這裡需要在views.py裡面新建l...

Django使用者登入與註冊系統

乙個很有趣的個人部落格,不信你來撩 fangzengye.com collapse n bar collapse id my n n n bar n active index 主頁 a li ul n n bar n n bar right a li logout 登出 a li login 登入 ...

django 的form登入 註冊

1 usr bin env python2 coding utf8 3 author skiler hao 4 date 2017 3 30 15 40 5from django.core.exceptions import validationerror 丟擲異常 6from django imp...