Reputation: 27
I am new to django. setup is ubuntu server. Have created a project, database, edited the settings.py, views.py, urls.py files. Created a template folder and a main_page.html file. All this from django:visual quickpro book. I keep getting a name error when I run the development server. It says the name 'main_page' is not defined.
Here is the urls.py;
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^$', main_page),
# Examples:
# url(r'^$', 'chapter2.views.home', name='home'),
# url(r'^chapter2/', include('chapter2.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)),
)
Here is the views.py;
# Create your views here
from django.http import HttpResponse
from django.template import Context
from django.template.loader import get_template
def main_page(request):
template = get_template('main_page.html')
variables = Context({'head_title': 'First Application',
'page_title': "Welcome to our first application',
'page_body': "This is our first application, pretty good, eh?'})
output = template.render(variables)
return HttpResponse(output)
I figure there is a syntax error in the book, it was catered to much for windows or I just am missing something obvious. I have worked on it for hours, but don't see the problem. I hope someone can help.
Thanks, Bobby
Upvotes: 1
Views: 1360
Reputation: 375774
At the top of your urls.py, add this:
import app.views # where "app" is the name of your app
Then change your line in urls.py to be this:
(r'^$', app.views.main_page),
Upvotes: 3