[英]Django Models: Where is Model class?
On documentation it has been said that each model is a python subclass of models.Model
class that is inside django folder
followed by db folder
. 在文档中,有人说每个模型都是
models.Model
类的python子类,它位于django folder
之后是db folder
。 When i look inside my django folder
i see a db folder
which was expected
and inside my db folder i see models folder
which contains lot of files. 当我在
django folder
查看时,我看到了一个expected
的db folder
,而在我的db文件夹中,我看到了包含很多文件的models folder
。 But I was expecting a models.py
package which contains Model
class. 但是我
expecting a models.py
包含Model
类expecting a models.py
包。 So my doubt is from where does this models.Model class come from? 所以我的疑问是这个model.Model类来自哪里?
This might be not a top level question but I am hopeful someone here will certainly help. 这可能不是一个顶级问题,但我希望这里的人一定会有所帮助。
Nope it's not magic it's django , it does exist if you go to the django's source code, you can see that the Model class exists , But in that way don't you had to import models in this way??: 不,这不是django的魔力,如果您进入django的源代码,它确实存在,您可以看到Model类存在 ,但是那样就不必以这种方式导入模型了吗?
from django.db.models.base import Model
Yes you can do it in that way, But django does it for you in the models/ __init__ file, so the only thing you have to do is: 是的,您可以通过这种方式进行操作,但是django在models / __init__文件中为您完成了操作,因此您唯一要做的就是:
from django.db import models
models refers to the models folder
inside django.db
but when you import it, it brings you all the things that are inse the models/____init__ .py file, I recommend you to read this models指的是
django.db
的models folder
,但是当您导入它时,它会带给您inmodels / ____ init__ .py文件中的所有内容,我建议您阅读此文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.