1、setting文件
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'models' #新增 ]
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'userinfo', 'USER': 'root', 'PASSWORD': 'root', 'HOST':'localhost', } }
2、view.py
import os os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoTest.settings' import django os.environ.setdefault('DJANGO_SETTING_MODULE', 'MyDjango.settings') django.setup() from models.models import Age if __name__ == '__main__': result = Age.objects.all() print(result)
3、model自动生成