-2

我收到此错误

Reverse for 'option' with arguments '('',)' and keyword arguments '{}' not found.

当我呈现我的选项页面时。选项页是 3 部分工作流中的最后一页。前 2 页工作正常。我不确定为什么没有渲染。我的代码如下:

视图.py

def drui_index(request):
  disease_list = Disease.objects.all()
  context = {'disease_list':disease_list, 'hide_breadcrumb': hide_breadcrumb}
  return render(request, 'drui_index.html', context)


def drui(request, disease_id):
  disease = get_object_or_404(Disease, pk=disease_id)  

  if request.method == "POST":
      indicatorInlineFormSet = IndicatorFormSet(request.POST, request.FILES, instance=disease)

      if indicatorInlineFormSet.is_valid():
         indicatorInlineFormSet.save()
         return HttpResponseRedirect(reverse('option', kwargs={'disease_id':disease_id}))

  else:
      indicatorInlineFormSet = IndicatorFormSet(instance=disease)

  return render(request, 'drui.html', {'disease':disease, 'indicatorInlineFormSet': indicatorInlineFormSet})


def option(request, disease_id):

     disease = get_object_or_404(Disease, pk=disease_id)

     if request.method == "POST":
         optionInlineFormSet = OptionFormSet(request.POST, request.FILES, instance=disease, prefix='option')
         outcomeInlineFormSet = OutcomeFormSet(request.POST, request.FILES, instance=disease, prefix='outcome')


        if optionInlineFormSet.is_valid() and outcomeInlineFormSet.is_valid:
           optionInlineFormSet.save()
           outcomeInlineFormSet.save()
           return HttpResponseRedirect(reverse('splash', kwargs={'disease_id':disease_id}))

    else:
        optionInlineFormSet = OptionFormSet(instance=disease,prefix='option')  
        outcomeInlineFormSet = OutcomeFormSet(instance=disease,prefix='outcome')

   return render(request, 'option.html', {'optionInlineFormSet': optionInlineFormSet, 'outcomeInlineFormSet': outcomeInlineFormSet})  

网址.py

url(r'^drui_index/$', 'Physician_UI.views.drui_index', name='drui_index'),
url(r'^drui_index/(?P<disease_id>\d+)/$', 'Physician_UI.views.drui', name='drui'),
url(r'^drui_index/(?P<disease_id>\d+)/option/$', 'Physician_UI.views.option', name='option'),

HTML drui_index.html

{% load url from future %}
<form class="disease_form" action="{% url "drui_index" %}" method="post">{% csrf_token %}

HTML drui.html

{% load url from future %}
<form class="disease_form" action="{% url "drui" disease.id %}" method="post">{% csrf_token %}

HTML option.html

 {% load url from future %}
 <form class="option_form" action="{% url "option" disease.id %}" method="post">{% csrf_token %}

正如我之前提到的,前 2 个页面(drui_index 和 drui)工作正常,但 option.html 没有。我包含了大部分代码,以防我以错误的方式传递信息。

我正在使用 django 1.4

4

1 回答 1

1

您应该在视图disease的上下文中传递对象。option您没有disease在上下文和正在使用的模板中传递对象,disease.id因此会出现错误。

return render(request, 'option.html',
    {'optionInlineFormSet': optionInlineFormSet,
    'outcomeInlineFormSet': outcomeInlineFormSet,
    'disease': disease})
于 2013-08-05T02:16:32.803 回答