importerror - how to understand dot notation in this Django blog app -
i learn book python web development django covers django 1.0 . on other hand, use django 1.5.1 , python 2.7.5 . stuck @ 'making blog's public side' session.
i open blog/views.py
file , type following:
from django.template import loader, context django.http import httpresponse mysite.blog.models import blogpost def archive(request): posts = blogpost.objects.all() t = loader.get_template('archive.html') c = context({ 'posts': posts }) return httpresponse(t.render(c))
next step, edit mysite/urls.py
looks this:
url(r'^blog/', include('mysite.blog.urls')),
and last step, make new file, mysite/blog/urls.py
, containing these lines:
from django.conf.urls.defaults import * mysite.blog.views import archive urlpatterns = patterns('', url(r'^$', archive), )
but, when try open http://127.0.0.1:8000/blog/
, arised exception value: no module named blog.urls
. after doing research, found problem little bit similar mine. so, based on exception value, edit mysite/urls.py
:
url(r'^blog/', include('blog.urls')),
i refresh web browser, exception occurs : no module named mysite.blog.views
. @ mysite/blog/urls.py
file contains mysite.blog.views
, edit it: from views import archive
. refreshing browser.
and...i 'oh ok..' when saw no module named mysite.blog.models
. edit from mysite.blog.models import blogpost
from models import blogpost
. finally, blog appears in browser.
my questions :
what technical explanation i've done , exceptions occur? i'm guessing edit other 2 files (the first 1 because see solution research). example, difference between
url(r'^blog/', include('blog.urls')),
,url(r'^blog/', include('mysite.blog.urls')),
? in beginner opinion, both true (even in first time, last 1 more 'complete')are these problems related django version use (1.5.1), book use django 1.0?
sorry long post want understand these stuff in detail. thanks!
Comments
Post a Comment