Django执行离线ORM、数据操作
- django执行离线ORM操作,方法1
import os
if __name__ == '__main__':
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "orm_demo.settings")
import django
django.setup()
from app01 import models
- django执行离线ORM操作,方法2
#1
python manage.py shell
#2
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
snippet = Snippet(code='foo = "bar"\n')
snippet.save()
snippet = Snippet(code='print "hello, world"\n')
snippet.save()
- django数据库操作
python manage.py inspectdb
python manage.py inspectdb