我是django的新手。一直在使用它,但仍然一直都是非常愚蠢的错误。不过这一点,我似乎很难搞清楚......因为我对此并不陌生,所以我不太擅长解释我的问题,但这里有......
错误消息在模板中抱怨此位:
{% url privblog object.id %}
urls.py extract:
urlpatterns = patterns('', url(r'^(?P<object_id>\d+)/$', 'privblog.views.privblog_detail', name="privblog"),)
views.py:
from django.shortcuts import render_to_response
from models import PrivBlog
from blog.models import Blog
from django.template import RequestContext
def privblog_detail(request, object_id=None):
pblog_detail_object = PrivBlog.objects.filter(id=object_id)
pblog_recent_object = PrivBlog.objects.all()[:5]
tblog_recent_object = Blog.objects.all()[:5]
context = {'pblog_detail_object': pblog_detail_object,
'pblog_recent_object': pblog_recent_object,
'tblog_recent_object': tblog_recent_object,
}
return render_to_response('privblog/privblog_detail.html', RequestContext(request, context))
答案 0 :(得分:2)
您的上下文中没有名为object的对象:
{% url privblog object.id %}
应该是
{% url privblog pblog_detail_object.id %}
你可能也遇到了麻烦:
return render_to_response('privblog/privblog_detail.html', context, RequestContext(request))
我从未以这种方式调用render_to_response。