[Django]-PyCharm not recognizing Django project imports: from my_app.models import thing

123πŸ‘

βœ…

I was having this issue using a β€œ2 Scoops of Django” project layout, e.g.

/project_root
    /project_dir
        /config
            /settings
        /my_app
            /tests
            models.py
    /requirements
    readme.rst

The code was working, but in /tests, IntelliJ/PyCharm showed an unresolved reference:

from my_app.models import Something

I had all the __init__.py files in place. I ended up having to set the sources root to project_dir:

Right-click on project_dir, Mark Directory as > Sources Root

2πŸ‘

Now that I can take a look over you project structure I can tell you that the problem appears to be related to a missing __init__.py in your β€˜src’ folder. Try adding an empty file named __init__.py in the root of β€˜src’ folder.

Also, take a look to this question, I think is the same problem or a very similar one.

Hope this could be useful, cheers!

πŸ‘€pazitos10

-2πŸ‘

I was having this issue after I change my environment to virtualenv, so I changed my python interpreter to my current virtualenv.

Go to File > Settings > Project Interpreter.
In that window you would be able to see all packages includes on this interpreter, Django should be there.

This worked for me.

Link about: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206598665-Unresolved-Reference-Errors-for-django

πŸ‘€Rafael Maciel

Leave a comment