django - python manage.py runserver works fine, but cannot run urls.py without getting import error -
i following djangobook website. starting out, , project structure looks this:
mysite     mysite         __init__.py         settings.py         urls.py         views.py         wsgi.py     manage.py   the outer mysite lives in directory on pythonpath. therefore, if want import views.py in python console, have construct import:
from mysite.mysite.views import hello   however, actual implementation in urls.py works when running server is:
from mysite.views import hello   if try import hello using single mysite relative import in console, fail. how come not fail when execute:
python manage.py runserver   ?
here traceback of failed import, , successful import:
(django_env) c:\>python python 3.5.2 |anaconda 4.1.1 (64-bit)| (default, jul  5 2016, 11:41:13) [msc                                      v.1900 64 bit (amd64)] on win32 type "help", "copyright", "credits" or "license" more information. >>> mysite.views import hello traceback (most recent call last):   file "<stdin>", line 1, in <module> importerror: no module named 'mysite.views' >>> mysite.mysite.views import hello >>>      
when run command via ./manage.py run django setup() django.setup , sets environment, can use
./manage.py shell   to run python django settings.
Comments
Post a Comment