我正在尝试访问我的上下文数据但由于某种原因我收到错误。
使用关键字参数“{'pk1':''}'反转'applicant_register3' 找不到
.....................................
{% extends 'base.html' %}
{% load static %}
{% block body %}
<div class="container paddingtop80 marginbottom30">
<div class="jumbotron greenback">
Test
<a href="{% url 'registration:applicant_register3' pk1=project.id %}" class="btn btn-success" role="button"><span class="glyphicon glyphicon-plus"></span> Add Applicants</a>
</div>
</div>
我正在尝试使用pk1 = project.id
我的观点应该允许我访问它..
class RecruitmentPage(generic.ListView):
#import pdb; pdb.set_trace()
template_name = "recruitment_index.html"
model = Project
def get_object(self, queryset=None):
return get_object_or_404(Project, id=self.kwargs['pk1'])
def get_context_data(self, **kwargs):
context = super(RecruitmentPage, self).get_context_data(**kwargs)
return context
我猜想通过在通用视图中提供模型我可以访问它,但似乎我不能..
有人可以帮我一把吗? thx
答案 0 :(得分:0)
您收到import tensorflow as tf
NODE_OPS = ['Placeholder','Identity']
MODEL_FILE = '/path/to/frozen_inference_graph.pb'
gf = tf.GraphDef()
gf.ParseFromString(open(MODEL_FILE,'rb').read())
print([n.name + '=>' + n.op for n in gf.node if n.op in (NODE_OPS)])
错误,因为NoRevereseMatch
不在模板上下文中。
列表视图不会自动调用您的project
方法。您可以使用get_object
方法手动调用它:
get_context_data
现在,在您的模板中,您可以使用class RecruitmentPage(generic.ListView):
#import pdb; pdb.set_trace()
template_name = "recruitment_index.html"
model = Project
def get_object(self, queryset=None):
return get_object_or_404(Project, id=self.kwargs['pk1'])
def get_context_data(self, **kwargs):
context = super(RecruitmentPage, self).get_context_data(**kwargs)
context['current_project'] = self.get_object()
return context
循环遍历所有项目的列表。
project_list
您可以使用{% for project in project_list %}
{% endfor %}
get_object
访问该项目
current_project