需要导入才能访问我的模型? [英] What do I need to import to gain access to my models?

查看:69
本文介绍了需要导入才能访问我的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个脚本来填充我的数据库。我想通过Django数据库API访问它。



唯一的问题是我不知道我需要导入以获得访问权限。



如何实现?

解决方案

导入您的设置模块也是

  import os 
os.environ [DJANGO_SETTINGS_MODULE] =mysite.settings

from mysite.polls.models import Poll,Choice

应该做的伎俩。 >

I'd like to run a script to populate my database. I'd like to access it through the Django database API.

The only problem is that I don't know what I would need to import to gain access to this.

How can this be achieved?

解决方案

Import your settings module too

import os
os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"

from mysite.polls.models import Poll, Choice

should do the trick.

这篇关于需要导入才能访问我的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆