[英]Is there an equivalent of “blah” + variable + “blah” in Angular?
[英]NoReverseMatch at /blah/blah/add though I thought my template if/else/endif would solve the error
我不断收到错误:
NoReverseMatch for 'grouplocation_add' with arguments '('',)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
编辑后添加context ['group_id'] =在createview上没有得到以下内容:
NoReverseMatch: Reverse for 'grouplocation_add' with arguments '(None,)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
模式:
url(r'^grouplocations/add/(?P<pk>[0-9]+)/$', GroupLocationCreateView.as_view(), name='grouplocation_add'),
再说一次,如果存在group_id的更新,它可以工作...如果它是新创建的,则不是,但是我认为我的{%if ...%}和{%else%}将处理这种情况。
我很确定当组ID不存在时,它是我url 'ipaswdb:grouplocation_add group_id
(如果在进行更新时正在调用它,但是创建一个新的组,但还没有ID, url 'ipaswdb:grouplocation_add group_id
。这是打开的按钮为已经创建的组做更多的事情。我的其他尝试是说“直到表单提交完毕,这样保存的模型才对模型进行更新视图...。”不要启用按钮,可让您与模型的其他部分混在一起,直到将其保存一次。
{% if group_id %}
<td><a href=""><button disabled type="button" id="group_add_location" class="btn btn-primary">Add A Group
Location</button></a> </td>
{% else %}
<td><a href="{% url 'ipaswdb:grouplocation_add' group_id %}"><button type="button" id="group_add_location" class="btn btn-primary">Add A Group
{% endif %}
鉴于错误显然我的方法是不同的。 我还想保存并返回到更新视图而不是创建视图。 那在我的意思是
class GroupCreateView(CreateView):
..do tons of stuf
def get_context_data(self, **kwargs):
..do more stuf
context['group_id'] = None #added this
def post(self, request, *args, **kwargs):
if self.request.POST.has_key('submit'):
..DO LOTS OF STUFF..
return HttpResponseRedirect("")
给定页面加载后,如果从updateView加载了该group_id,那么它是否存在,那么我是否需要HttpResponseRedirect以某种方式转到UpdateView? 我怎样才能从创建视图中保存保存的模型并将其直接传递给updateview?
1)因此,我猜两件事:如果它在if else块中,为什么会给出该错误。
2)修复该错误后,如何通过有效地从创建视图(具有HttpResponseRedirect的一端)转过头来调用ifView块,并使用新创建的模型调用UpdateView,从而获得一个group_id(通过进入UpdateView的顶点)
因为在您的else语句中group_id为none。 因此,您应该将该字段指定为none。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.