好的,所以我是一个菜鸟,用 python 在 django 中构建一个基本站点。我正在尝试在我的站点中实现一个名为编辑区域的新页面。每当我访问该页面时,我得到的就是这个......
NameError at /
name 'editareapage' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.1
Exception Type: NameError
Exception Value:
name 'editareapage' is not defined
我的观点.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
import datetime
def hello(request):
return HttpResponse("Hello, World!")
def mainpage(request):
return render_to_response('mainpage.html')
def current_datetime(request):
now = datetime.datetime.now()
return render_to_response('current_datetime.html', {'current_time':now})
def hours_ahead(request,offset):
try:
offset= int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset,dt)
return HttpResponse(html)
def editareapage(request):
return render_to_response('editareapage.html')
另外值得注意的是editareapage是我试图访问的那个。
这是我的 urls.py
from django.conf.urls import patterns, include, url
from MyProj.views import hello,mainpage, current_datetime, hours_ahead
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^hello/$', hello),
(r'^$', mainpage),
(r'^time/$',current_datetime),
(r'^time/plus/(\d{1,2})/$', hours_ahead),
(r'^editareapage/$', editareapage),
# Examples:
# url(r'^$', 'MyProj.views.home', name='home'),
# url(r'^MyProj/', include('MyProj.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:
(r'^admin/', include(admin.site.urls)),
)
希望这足以让某人帮助我,谢谢!