django- initialize the database data script

Import OS
 Import SYS
 Import Django 

base_dir = os.path.dirname (os.path.dirname (os.path.abspath with ( __FILE__ ))) 
sys.path.append (base_dir) 

# The path to the configuration file is written in the environment variables DJANGO_SETTINGS_MODULE 
os.environ.setdefault ( " the DJANGO_SETTINGS_MODULE " , " demos.settings " ) 
django.setup () 

from API Import Models 
models.Topic.objects.create (title = " spring Festival " ) 
models.Topic.objects.create (title = " tickets ")

 

Guess you like

Origin www.cnblogs.com/a438842265/p/12461365.html