django book的第一个例子

上来就是门棍

在openstack (django 1.9)上报告出错。

错误如下

coercing to Unicode: need string or buffer, HttpResponse found

修正后的例子如下

views.py

def fx(request):
   now = datetime.datetime.now()
   html = "fx" 
   return HttpResponse(html)

urls.py

from django.conf.urls import patterns
from django.conf.urls import url

from openstack_dashboard.dashboards.project.diyiti import views


urlpatterns = patterns('openstack_dashboard.dashboards.project.diyiti.views',
    url(r'^$', views.CourseOverview.as_view(), name='index'),
    url(r'^create/$', views.CreateView.as_view(), name='create'),
    url(r'^date/$', 'fx')
)
root@node-9:/usr/share/openstack-dashboard# 

出错的原因,需要将HttpResponse标记为__unicode__, 所以在urls.py里不应该是

    url(r'^date/$', fx)

而应该是

    url(r'^date/$', 'fx')

你可能感兴趣的:(django book的第一个例子)