我是Django编码的新手......我想在area_distnce.html中显示任何内容......下面是我的代码
提前致谢....
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.context import RequestContext
def area_distance(request):
return render_to_response('area_distance.html',locals(),context_instance=RequestContext(request))
from django.conf.urls import patterns, include, url
from areas.Distance import area_distance
urlpatterns = patterns('',
url(r'^area/$','area_distance',name = 'area_distance'),)
当我跑他的时候就是给予 / area /的TypeError 'str'对象不可调用
答案 0 :(得分:0)
您似乎在area_distance()
而不是Distance.py
中编写了视图功能views.py
。
因此,您可能希望更新urls.py
以正确使用
url(r'^area/$', area_distance,name = 'area_distance'),)
---------------^ note no '...'
正如您所做的from areas.Distance import area_distance
这应该有用。
答案 1 :(得分:0)
from django.http import HttpResponse
from django.template.context import RequestContext
def area_distance(request):
a= 1
b = a+1
t = get_template('area_distance.html')
c = RequestContext(request, locals())
return HttpResponse(t.render(c))
#url.py
from django.conf.urls import patterns, include, url
from areas.Distance import area_distance
urlpatterns = patterns('',
url(r'^area/$',area_distance,name = 'area_distance'),)
#template
{{ a }}
{{ b }}