0

I'm trying to run a django app but hitting this error when trying to load the page from the browser:

No module named views

The offending line in urls.py is

from landpage.views import txt

The file structure looks like this:

UPDATED

/myproject
    /myproject
        settings.py
    manage.py
    /landpage
        __init__.py
        models.py
        urls.py
        /views
            __init__.py
            landpage.py
            txt.py

I've run the command python manage.py check --traceback and gotten the result System check identified no issues (0 silenced).

I'm very new to django so I am not sure what else to check or what might be causing the issue. This project was just cloned. I have not changed anything.

UPDATE

Adding __init__.py under the views folder fixed this error. There is a new one now in landpage.py at the line from landpage.models import LandpageTeamMember which says No module named models.

Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
  • where is manage.py located? – dahrens Jan 20 '17 at 22:23
  • @dahrens updated the question with more detailed file structure – Kevin_TA Jan 20 '17 at 22:28
  • Does your landpage folder contains `__init__.py` - it needs one to be treaten as a package. – dahrens Jan 20 '17 at 22:41
  • It does. It is an empty file. – Kevin_TA Jan 20 '17 at 22:46
  • Is there also `__init__.py` file in views directory? If yes and it is still not working. Open a django python shell in your projects root folder like that `python manage.py shell`. Try to import there. If there are errors do `import sys; print(sys.path)`. This should show you all root folder from which python tries to import packages and modules. Read for more information: http://stackoverflow.com/questions/7948494/whats-the-difference-between-a-python-module-and-a-python-package – dahrens Jan 20 '17 at 22:55
  • @dahrens, adding `__init__.py` fixed this error but there is a now a different similar one. See updated question and file structure. Also, I don't see anything glaringly wrong with the `sys.path`. I see what I expect to be the root folder and then a ton of virtualenvs paths. – Kevin_TA Jan 20 '17 at 23:06
  • there is a module called landpage that imports from a package with the same name, that lives two lvls above? I don't know - but maybe this causes the issue - have you already checked the last few commits of the repository? – dahrens Jan 20 '17 at 23:15
  • ya know what? I just saw that Python 3 is a requirement. I am using Python 2.7... That must be it, right? – Kevin_TA Jan 20 '17 at 23:24
  • You should also check that virtualenv path thingy above - I'm afraid you'll need to learn about dependency management in python on top. Leave and remove your venv. Setup a fresh one. If the project is well maintained it ships requirements.txt. Use pip in your fresh environment to install external dependencies. – dahrens Jan 20 '17 at 23:30

2 Answers2

3

Try putting a __init__.py inside the views directory.

NS0
  • 6,016
  • 1
  • 15
  • 14
0

You can change from

landpage.views import txt

to

myproject.landpage.views import txt

So error says that it cannot import, because it cannot find landpage.views here. try to go to shell

./manage.py shell

then in shell try to import

from myproject.landpage.views import txt

if there is no error then you are good

Dmitry Yudin
  • 1,033
  • 1
  • 10
  • 31
  • This gives the new error `No module named landpage.views` – Kevin_TA Jan 20 '17 at 22:46
  • If you have errors with your projects imports (and someone else obviously started on the project) you should start investigating your environment, __before__ you change the imports. – dahrens Jan 20 '17 at 23:00
  • but investigation using the django shell is a nice approach! :) – dahrens Jan 20 '17 at 23:04