0
所以我有一个显示基于对从主页搜索的人的一些数据的视图调用视图:的Django从另一种观点认为
def film_chart_view(request):
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
# grab the first person on the list
try:
person_search = Person.objects.filter(short = q)[0]
filminfo = filmInfo(person_search.film_set.all())
film_graph_data = person_search.film_set.all().order_by('date')
#Step 1: Create a DataPool
return render_to_response('home/search_results.html',{'query': q, 'high': filminfo[0],
'graph_data': film_graph_data}, RequestContext(request))
except IndexError:
return render_to_response('home/not_found.html',{'query': q}, RequestContext(request))
在主页上我也希望有一个随机按钮显示来自数据库中随机人员的一些数据并用上述视图显示。到目前为止,我有这样的观点:
def random_person(request):
# 1282302 is max number of people currently
get_random = random.randint(1,1282302)
get_person = Person.objects.get(pk=get_random)
person_name = get_person.full
,但我不知道怎么那么它重定向到film_chart_view完成它。
我越来越: “NoReverseMatch在/随机/ 反向的‘film_chart_view’与参数‘()’和关键字参数'{}' 未找到。” 我在urls.py的网址是: url(r'^ random/$','home.views.random_person'), – dl8
@ user2027556,尝试将它改为'HttpResponseRedirect(reverse('home.views。 film_chart_view')+ “?q =” + get_person.short)'。我假设你也为此添加了网址。 – Rohan
我得到“ValueError at/random/ 视图home.views.random_person没有返回HttpResponse对象。”现在 – dl8