django聯(lián)系人登錄界面案例詳解
目前還在學習中,這是一個簡單的小案例,有錯誤的話,請批評指。
注意:此案例的運行前提是配置好python環(huán)境,MySQL環(huán)境,django環(huán)境
預覽
代碼實現(xiàn)
html界面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>聯(lián)系人在線管理系統(tǒng)</title> <link rel="stylesheet" href="/static/plugins/bootstrap-3.4.1-dist/css/bootstrap.css" rel="external nofollow" > <style> .account{ width:500px; height:320px; border:2px solid #999999; border-radius:20px; margin-left:auto; margin-right:auto; margin-top:200px; padding:20px 40px; } .h1{ text-align:center; } .h2{ color:#3887B6; } .b3{ background-color:#C04849; border-radius:10px; color:#FFFFFF; display:block; margin:0 auto; margin-top:30px; width:350px; height:40px; box-shadow:5px 5px 10px #A3ADA4; } </style> </head> <body> <form method="post" class="account"> {% csrf_token %} <h1 class="h1 h2">聯(lián)系人在線管理系統(tǒng)</h1> <div class="form-group" style="margin-top:10px;"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> <label id="exampleInputEmail1">用戶名</label> {{form.username}} {{form.username.error.0}} <span style="color:red;font-size:12px">{{font.username.error.0}}</span> </div> <div class="form-group" style="margin-top:10px;"> <span class="glyphicon glyphicon-signal" aria-hidden="true"></span> <label id="exampleInputPassword1">密碼</label> {{form.password}} {{form.password.error.0}} <span style="color:red;font-size:12px">{{font.password.error.0}}</span> </div> <div> <input type="submit" value="登錄" class="b3"> </div> </form> <script src="/static/js/jquery-3.7.1.min.js"></script> <script src="/static/plugins/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script> </body> </html>
此界面引入了css和js,連接了mysql數(shù)據(jù)庫
views.py
class LoginForm(forms.Form): username = forms.CharField( label="用戶名", widget=forms.TextInput(attrs={'class': 'form-control', "placeholder": "請輸入用戶名"}), required=True ) password = forms.CharField( label="密碼", widget=forms.PasswordInput(attrs={'class': 'form-control', "placeholder": "請輸入密碼"}), required=True ) def clean_password(self): pwd = self.cleaned_data.get("password") return md5(pwd)
密碼用了md5加密,引入的庫包括以下幾個:
from django.shortcuts import render, redirect, HttpResponseRedirect from contacts import models from django import forms from django.core.validators import RegexValidator from contacts.encrpty import md5 from django.utils.safestring import mark_safe from django.shortcuts import get_object_or_404
urls.py
urlpatterns = [ path("admin/", admin.site.urls), path("getUser/", views.getUser),]
models.py
class Login(models.Model): username = models.CharField(verbose_name="用戶名",max_length=32) password = models.CharField(verbose_name="密碼",max_length=32)
最后,打開終端輸入
python manage.py runserver
到此這篇關于django聯(lián)系人登錄界面的文章就介紹到這了,更多相關django聯(lián)系人登錄界面內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python備份目錄及目錄下的全部內容的實現(xiàn)方法
下面小編就為大家?guī)硪黄狿ython備份目錄及目錄下的全部內容的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06python中的torch常用tensor處理函數(shù)示例詳解
這篇文章主要介紹了python中的torch常用tensor處理函數(shù),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07python3.8.1+selenium實現(xiàn)登錄滑塊驗證功能
這篇文章主要介紹了python3.8.1+selenium解決登錄滑塊驗證的問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05python aiohttp創(chuàng)建很多線程的問題及解決
這篇文章主要介紹了python aiohttp創(chuàng)建很多線程的問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06Python將json文件寫入ES數(shù)據(jù)庫的方法
這篇文章主要介紹了Python將json文件寫入ES數(shù)據(jù)庫的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-04-04