I have been running into this error for the past day and can\'t seem to solve it.
Reverse for \'\' with arguments \'(7,)\' and keyword arguments \'{}\' not
I think you are missing quotes around url name:
{% url drui disease.id %}
Should be (if you are using django >= 1.5) or using {% load url from future %}
in template:
{% url "drui" disease.id %}
Your url
tag should be {% url "drui" disease_id=disease.id %}
, because you need to pass in the keyword argument.
See the documentation for more information.
As you never save the new entry, I think you are just using the form to display the ModelChoiceField
, in that case you don't need a ModelForm
:
class DiseaseForm(forms.Form):
disease = forms.ModelChoiceField(queryset=Disease.objects.all())
That way, you avoid the commit=False
part.
You should always have an else
for your if form.is_valid()
:
from django.shortcuts import redirect
def drui(request, disease_id):
disease = get_object_or_404(Disease, pk=disease_id)
ctx = {}
ctx['disease'] = disease
ctx['indicatorInlineFormSet'] = IndicatorFormSet()
ctx['diseaseForm'] = DiseaseForm()
if request.method == "POST":
diseaseForm = DiseaseForm(request.POST)
indicatorInlineFormSet = IndicatorFormSet(request.POST, request.FILES)
if diseaseForm.is_valid():
return redirect('drui', disease_id=disease_id)
else:
# Form wasn't valid, return the same view to display the errors
ctx['diseaseForm'] = diseaseForm
ctx['indicatorInlineFormset'] = indicatorInlineFormset
return render(request, 'drui.html', ctx)
else:
return render(request, 'drui.html', ctx)