django聯(lián)系人登錄界面案例詳解
目前還在學(xué)習(xí)中,這是一個(gè)簡(jiǎn)單的小案例,有錯(cuò)誤的話,請(qǐng)批評(píng)指。
注意:此案例的運(yùn)行前提是配置好python環(huán)境,MySQL環(huán)境,django環(huán)境
預(yù)覽
代碼實(shí)現(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": "請(qǐng)輸入用戶名"}), required=True ) password = forms.CharField( label="密碼", widget=forms.PasswordInput(attrs={'class': 'form-control', "placeholder": "請(qǐng)輸入密碼"}), required=True ) def clean_password(self): pwd = self.cleaned_data.get("password") return md5(pwd)
密碼用了md5加密,引入的庫包括以下幾個(gè):
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
到此這篇關(guān)于django聯(lián)系人登錄界面的文章就介紹到這了,更多相關(guān)django聯(lián)系人登錄界面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python備份目錄及目錄下的全部?jī)?nèi)容的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狿ython備份目錄及目錄下的全部?jī)?nèi)容的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06python中的torch常用tensor處理函數(shù)示例詳解
這篇文章主要介紹了python中的torch常用tensor處理函數(shù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07Python設(shè)計(jì)模式優(yōu)雅構(gòu)建代碼全面教程示例
Python作為一門多范式的編程語言,提供了豐富的設(shè)計(jì)模式應(yīng)用場(chǎng)景,在本文中,我們將詳細(xì)介紹 Python 中的各種設(shè)計(jì)模式,包括創(chuàng)建型、結(jié)構(gòu)型和行為型模式2023-11-11python3.8.1+selenium實(shí)現(xiàn)登錄滑塊驗(yàn)證功能
這篇文章主要介紹了python3.8.1+selenium解決登錄滑塊驗(yàn)證的問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05python aiohttp創(chuàng)建很多線程的問題及解決
這篇文章主要介紹了python aiohttp創(chuàng)建很多線程的問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06Python將json文件寫入ES數(shù)據(jù)庫的方法
這篇文章主要介紹了Python將json文件寫入ES數(shù)據(jù)庫的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-04-04