I’ve been trying to get django set up so I can start learning it. But I can’t even display even a simple view. Here’s my file structure:
âââ __init__.py
âââ __init__.pyc
âââ manage.py
âââ media
âââ pages
â  âââ views.py
âââ settings.py
âââ settings.pyc
âââ templates
â  âââ base.html
â  âââ home.html
âââ urls.py
âââ urls.pyc
Sorry about the weird sybols, that’s how the linux computer printed it out with the tree command. Here’s my url file:
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'testsite.pages.views.home', name='home'),
# url(r'^testsite/', include('testsite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls))
)
Basically, I want example.com to point to the pages.views.home view. But it can’t find it and keeps giving me the error: Could not import testsite.pages.views. Error was: No module named pages.views
I’m new to both python and django so I’m probably doing something stupidly simple. Thanks in advance!
You need to add
__init__.pyto yourpagesdirectory, to make it a “package” in python parlance.This is a bit of non-obvious behaviour from python. Now you know.