Hello_World!!!

导航

 

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自动生成

posted on 2019-09-18 00:59  Hello_World!!!  阅读(1715)  评论(0编辑  收藏  举报