7
7
7761662018-06-08 21:56:29
Django
776166, 2018-06-08 21:56:29

Why don't Django views in the views folder see the model?

We have an application with a views folder for views. It has __init__.py, as expected. We have a folder for models. Everything seems to be normal. Django itself sees the models.
I am formed from the url to the view file, which should import the model. And she says that ImportError: No module named models. If you put the view in the root, correct the import in the URLs, then everything works. Near 100500 similar applications that work. Moreover, it also worked, and then stopped.
What could be the problem? I have already recreated, renamed, copied, but no, it does not want to work from the folder. __init__.pydjango sees, *.pyccreates, but the model does not import.
UPD: The problem was in the name of the application ( messaging), which, apparently, overlapped with something system.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tema_sun, 2018-06-09
@776166

I didn’t have to organize the code like that, but in this version you need to either use the full path to the models, ala from proj.app.models, or try relative import from ..models
And by the way

2) There is no import in __init__.py for models, it is empty.
, and it should be:
https://docs.djangoproject.com/en/2.0/topics/db/mo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question