1、環(huán)境搭建
需安裝:
python3.6
Pycharm專業(yè)版
django 2.2.6
mysqlclient
pip install django==2.2.6
pip install mysqlclient
2、生成django項(xiàng)目
django-admin startproject yourproject
3、修改數(shù)據(jù)庫(kù)引擎為mysql并要數(shù)據(jù)庫(kù)中創(chuàng)建對(duì)應(yīng)名字的數(shù)據(jù)庫(kù)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myblog', #數(shù)據(jù)庫(kù)名
'USER':'root', #用戶名
'PASSWORD':'******', #密碼
'HOST':'127.0.0.1', #本機(jī)地址
'PORT':'3306', #端口
}
}
pip install mysqlclient
4、初始化數(shù)據(jù)庫(kù)
python ./manage.py makemigrations
python ./manage.py migrate
5、漢化(修改項(xiàng)目settings.py)
LANGUAGE_CODE = 'zh-hans'
6、啟動(dòng)django項(xiàng)目
cd yourproject
python ./manage.py runserver 0.0.0.0:8000
7、創(chuàng)建django后臺(tái)管理員
python ./manage.py createsuperuser
8、創(chuàng)建自己的app
python .\manage.py startapp yourapp
9、定義app的數(shù)據(jù)模型model.py
from django.db import models
# Create your models here.
class SinfoM(models.Model):
description=models.CharField(max_length=50,verbose_name='描述',null=False,blank=False)
username=models.CharField(max_length=50,verbose_name='賬號(hào)',null=False,blank=False)
password=models.CharField(max_length=50,verbose_name='密碼',null=False,blank=False)
remark=models.CharField(max_length=50,verbose_name='備注',null=True,blank=True)
class Meta:
db_table=u'self_info'
verbose_name=u'個(gè)人信息'
verbose_name_plural=u'個(gè)人信息'
def __unicode__(self):
return self.username
def __str__(self):
return self.username
10、在app的admin中定義頁(yè)面顯示內(nèi)容
from django.contrib import admin
# Register your models here.
from sinfom.models import SinfoM
class SinfoMAdmin(admin.ModelAdmin):
# exclude = ('password')
list_display = (
'description',
'username',
'password',
'remark'
)
admin.site.register(SinfoM,SinfoMAdmin)
11、重新執(zhí)行數(shù)據(jù)庫(kù)腳本
python ./manage.py makemigrations
python ./manage.py migrate
12、將app注冊(cè)到項(xiàng)目的settings.py中
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'yourapp',
]
13、Pycharm專業(yè)版Debug配置及頁(yè)面展示效果
備注:
生產(chǎn)環(huán)境settings.py
到此這篇關(guān)于Django一小時(shí)寫出賬號(hào)密碼管理系統(tǒng)的文章就介紹到這了,更多相關(guān)Django 賬號(hào)密碼管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- django中賬號(hào)密碼驗(yàn)證登陸功能的實(shí)現(xiàn)方法