新建项目,并开启
python manage.py runserver 8080
访问admin页面
http://127.0.0.1:8080/admin
补充:若是发现admin页面样式丢失:可能是因为在settings文件中的数据格式写错了,比如:
STATICFILES_DIRS 是元组类型,若是在os.path.join(BASE_DIR,'static')后面忘记加上逗号分隔符,则可能会丢失样式,无法找到
STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), )
此时并没有账号和密码:需要先配置数据库,在生成用户
配置数据库
python manage.py makemigrations
python manage.py migrate
创建用户
python manage.py createsuperuser
需要填写用户名,邮箱,密码
管理Django数据库的APP--->phpmyadmin,web版管理数据库
创建数据表:
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models # Create your models here. class Publisher(models.Model): name = models.CharField(max_length=30, verbose_name="名称") address = models.CharField("地址", max_length=50) city = models.CharField('城市', max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() class Meta: verbose_name = '出版商' verbose_name_plural = verbose_name def __str__(self): return self.name class Author(models.Model): name = models.CharField(max_length=30) def __str__(self): return self.name class AuthorDetail(models.Model): sex = models.BooleanField(max_length=1, choices=((0, '男'), (1, '女'),)) email = models.EmailField() address = models.CharField(max_length=50) birthday = models.DateField() author = models.OneToOneField(Author) class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField() price = models.DecimalField(max_digits=5, decimal_places=2, default=10) def __str__(self): return self.title