2012-07-22 3 views
1

저는 django를 처음 사용합니다. 설치 우분투 서버입니다. 프로젝트, 데이터베이스를 생성하고 settings.py, views.py, urls.py 파일을 편집했습니다. 템플릿 폴더와 main_page.html 파일을 만들었습니다. django의 모든 것 : visual quickpro book. 개발 서버를 실행할 때 계속 이름 오류가 발생합니다. 'main_page'라는 이름이 정의되어 있지 않습니다.예외 이름 'main_page'가 정의되지 않았습니다.

다음은 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)), 
) 

다음은 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) 

, 그것은 창에 대한 많은 음식을 장만했다 또는 그냥 뭔가를 분명 실종. 나는 몇 시간 동안 그 일을 해왔지만 문제는 보지 못했다. 누군가가 도울 수 있기를 바랍니다.

감사합니다, 바비

답변

3

당신의 urls.py의 상단이 추가 :

(r'^$', app.views.main_page), 
+0

감사 :

import app.views # where "app" is the name of your app 

다음이 될 urls.py에서 줄을 변경 . 여기 저기에 몇 가지 구문 오류를 수정해야했지만 마침내 작동합니다. – user78448

관련 문제