python - ImportError: No module named 'users' -


when run python /manage.py runserver , generates following error.

importerror: no module named 'users' 

i thinking error, maybe had mistake app setting.

$tree

. ├── license ├── readme.md ├── functional_test.py ├── requirement │   ├── development.txt │   └── production.txt ├── users │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init__.cpython-35.pyc │   │   ├── tests.cpython-35.pyc │   │   └── views.cpython-35.pyc │   ├── tests.py │   └── views.py └── wef     ├── db.sqlite3     ├── manage.py     └── wef         ├── __init__.py         ├── __pycache__         │   ├── __init__.cpython-35.pyc         │   ├── settings.cpython-35.pyc         │   └── urls.cpython-35.pyc         ├── settings.py         ├── urls.py         └── wsgi.py 

i think not problem.

2nd, maybe don't insert 'users' in settings.py

in settings.py

installed_apps = [     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',      'debug_toolbar',     'django_extensions',      'users', ] 

i have double check these situations.

here's code:

urls.py

from django.conf.urls import url django.contrib import admin  users.views import joinusview  urlpatterns = [     url(r'^admin/', admin.site.urls),     url(r'^$', user, name='home'), ] 

users/views.py

from django.http import httpresponse   def user(request):     return httpresponse("hello world") 

you import error because users directory not on python path. easiest solution move users directory project wef directory (the 1 contains manage.py).

└── wef     ├── db.sqlite3     ├── manage.py     ├── users     │   ├── __init__.py     │   ├── __pycache__     ...     └── wef         ├── __init__.py         ├── __pycache__         │   ├── __init__.cpython-35.pyc         │   ├── settings.cpython-35.pyc         │   └── urls.cpython-35.pyc         ├── settings.py         ├── urls.py         └── wsgi.py 

this work because ./manage.py adds project directory python path. if users directory outside of project directory, have modify python path yourself.


Comments