Answer the question
In order to leave comments, you need to log in
How to query django database not from views.py?
Good afternoon!
How to make a database query in Django not from views.py?
For example there is a file which is in test.py file in django application directory
Its content is
from company.models import *
company = Company.objects.all()
print(company)
python3 test.py
Traceback (most recent call last):
File "company/test.py", line 1, in <module>
from company.models import *
ModuleNotFoundError: No module named 'company'
Answer the question
In order to leave comments, you need to log in
Django needs to be initialized so that its ORM can be used. But it's better not to do this, most likely there are better ways to solve your problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question