Forums

ImportError: attempted relative import with no known parent package

I am having this error "ImportError: attempted relative import with no known parent package" Thou, my applications is working all fine but everytime this error appears. Please suggest what to do, I couldn't find relevant answer on google too.

How does the code look like?

I

![views.py][1] https://ibb.co/2SzW13L I have two applications on pythonanywhere, both have same error.

In url.py,following error occurs: https://ibb.co/5B9drxf

It looks like you're trying to run one of the files that is part of a Django site from the editor, which won't work -- the Django configuration and the system path won't be set up correctly. What are you aiming to do by running the files from there?

I tried to import models from admin.py to have access in admin panel. Here: https://ibb.co/xXSLMsL

It looks like you're trying to run one of the files that is part of a Django site from the editor, which won't work -- the Django configuration and the system path won't be set up correctly.

So solution is?

Don't try to run that file in the editor. Doing relative imports like that will not work when the file that you're running is the top level file, because there is nothing for the import to be relative to. When you run that file as part of the Django app, the parent package will be defined and the import should work (that is assuming that the models that you are trying to import are defined in /home/ptesol/ptesolpro/ptesolapp/models.py)

So How I can access my tables from models in django admin panel. Because everything was in parent package only already.

I can leave it like that, it will work, right?

It might work - whether it works depends on the things that I mentioned in my previous post.