exploit
2/13/2019 - 12:22 PM

django 数据库

在settings.py 里面加入


<app_name> blog.apps.BlogConfig

然后

python manage.py makemigrations blog 
python manage.py sqlmigrate blog 0001 

数据库操作

python manage.py shell

正常存取

from django.contrib.auth.models import User
from blog.models import Post
u = User.objects.get(username='admin')
post = Post(title='1',slug='2',body='hey',author=u)
post.save()

update: 直接使用数据库对象重新赋值即可 通过queryset对象,获取数据库的值

Post.objects.all()
Post.objects.filter(publish__year=2019)
Post.objects.filter(publish__year=2019).exclude(title__startswith='why')
Post.objects.order_by('-title')
post = Post.objects.get(id=1)
post.delete()