首页 > 代码库 > django项目基础
django项目基础
D:\>django-admin startproject GodWork1
D:\>cd GodWork1
D:\GodWork1>python manage.py startapp User
D:\GodWork1>python manage.py startapp Log
D:\GodWork1>python manage.py startapp Api
D:\GodWork1>python manage.py startapp Service
在User 的app下进行模型的定义
class User(models.Model):
username=models.CharField(max_length=32,verbose_name="用户名")
password=models.CharField(max_length=32,verbose_name="密码")
email=models.EmailField(verbose_name="邮箱")
phone=models.CharField(max_length=28,verbose_name="用户手机",blank=True,null=True)
photo=models.ImageField(upload_to="image/userPhoto",verbose_name=‘用户头像‘,blank=True,null=True)
class Group(models.Model):
name=models.CharField(max_length=32,verbose_name=‘组名称‘)
class Method(models.Model):
name=models.CharField(max_length=32,verbose_name="权限名称")
在Log 的app下进行模型的定义
class Log(models.Model):
user=models.CharField(max_length=32,verbose_name="用户名称")
time=models.DateTimeField(verbose_name="日志时间")
operation=models.CharField(max_length=128,verbose_name="操作")
level=models.IntegerField(verbose_name="日志等级")
types=models.CharField(max_length=16,verbose_name="日志类型")
在Service 的app下进行模型的定义
class Service(models.Model):
host=models.CharField(max_length=32,verbose_name="主机名称")
ip=models.CharField(max_length=32,verbose_name="主机IP")
mac=models.CharField(max_length=32,verbose_name="mac")
cpu=models.CharField(max_length=32,verbose_name="cpu")
mem=models.CharField(max_length=32,verbose_name="内存")
disk=models.CharField(max_length=32,verbose_name="磁盘")
system=models.CharField(max_length=32,verbose_name="系统")
model=models.CharField(max_length=32,verbose_name="服务器型号")
D:\GodWork1>python manage.py check
System check identified no issues (0 silenced).
D:\GodWork1>
D:\GodWork1>
D:\GodWork1>
D:\GodWork1>python manage.py makemigrations
Migrations for ‘Service‘:
0001_initial.py:
- Create model Service
Migrations for ‘Log‘:
0001_initial.py:
- Create model Log
Migrations for ‘User‘:
0001_initial.py:
- Create model Group
- Create model Method
- Create model User
D:\GodWork1>python manage.py syncdb
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages
django\core\management\commands\syncdb.py:24: RemovedInDjango19Warning: The syn
db command will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDj
ngo19Warning)
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: contenttypes, sessions, Service, auth, Log, admin, User
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying Log.0001_initial... OK
Applying Service.0001_initial... OK
Applying User.0001_initial... OK
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
You have installed Django‘s auth system, and don‘t have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use ‘administrator‘): admin
Email address: admin@qq.com
Password:
Password (again):
Superuser created successfully.
django项目基础