需安装:
python3.6
Pycharm专业版
django 2.2.6
mysqlclient
pip install django==2.2.6 pip install mysqlclient
django-admin startproject yourproject
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'myblog', #数据库名 'USER':'root', #用户名 'PASSWORD':'******', #密码 'HOST':'127.0.0.1', #本机地址 'PORT':'3306', #端口 } } pip install mysqlclient
python ./manage.py makemigrations python ./manage.py migrate
LANGUAGE_CODE = 'zh-hans'
cd yourproject python ./manage.py runserver 0.0.0.0:8000
python ./manage.py createsuperuser
python .\manage.py startapp yourapp
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='账号',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'个人信息' verbose_name_plural=u'个人信息' def __unicode__(self): return self.username def __str__(self): return self.username
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)
python ./manage.py makemigrations python ./manage.py migrate
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'yourapp', ]
备注:
生产环境settings.py
ALLOWED_HOSTS = [*]
到此这篇关于Django一小时写出账号密码管理系统的文章就介绍到这了,更多相关Django 账号密码管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!