尝试运行我的项目时出现名称错误,
网址.py
import os
from django.conf.urls.defaults import patterns, include, url
#from bookmarks.views import *
from django.views.generic.simple import direct_to_template
from preview.views import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^catalog/$', home),
)
视图.py
# Create your views here.
from django.shortcuts import render_to_response
def home(request):
return render_to_response("index.html")
索引.html
{% extends base.html %}
{% block content %}
<h2>Welcome!</h2>
{% endblock %}
设置.py
TEMPLATE_DIRS = (
"C:/python27/Djangoprojects/ecomstore/preview",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
错误
NameError at /catalog/
name 'home' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/catalog/
Django Version: 1.3.1
Exception Type: NameError
Exception Value:
name 'home' is not defined
Exception Location: C:\Python27\Djangoprojects\ecomstore\..\ecomstore\urls.py in <module>, line 12
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2