0
好吧,所以我是一個noob在python中用django構建一個基本站點。我正在嘗試在我的站點中實現一個名爲編輯區域的新頁面。每當我訪問的頁面我得到的是這樣...NameError at/name'editareapage'沒有被定義
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
我views.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)),
)
希望這是足以讓有人爲幫助我,謝謝!