一,创建项目App
python manage.py startapp App
二,在App.models.py中创建类,以下是示例
class UserModel(models.Model):
uid = models.AutoField(primary_key=True, auto_created=True)
name = models.CharField(max_length=10, unique=True, db_index=True, null=True)
age = models.IntegerField(default=18)
sex = models.BooleanField(default=True)
info = models.TextField(null=True, blank=True)
salary = models.FloatField(default=100000000.0)
money = models.DecimalField(max_digits=4, decimal_places=2,default=100.0)
三,在App.admin.py中添加如下代码
from App.model import *
admin.site.register(UserModel)
四,添加管理员用户
(.venv) PS D:\Pycharm Professional New Project\djangoProject3> python manage.py createsuperuser
Username (leave blank to use 'junmoxiao'): one_inch_ash
Email address: 2713783104@qq.com
Password:
Password (again):
Superuser created successfully.
(.venv) PS D:\Pycharm Professional New Project\djangoProject3>
五,启动项目
python manage.py runserver
六,访问以下网址
http://127.0.0.1:8000/admin
若想显示中文,则可以 在setting.py中修改
LANGUAGE_CODE = 'en-us'
为
LANGUAGE_CODE = 'zh-hans'