If I pass in a variable to the template like return render_to_response("grading_school_form.html", RequestContext(request, { "formset": formset, "pk":school_id, "spk":1})) then in the template {% for form in formset %}
<tr> <td>{{ spk }}</td> <td>{{ form.first_name }}</td> <td>{{ form.last_name}}</td> <td>{{ form.schoolName }}</td> <td><a href="{% url 'contest:gradingstudent' school_id=pk student_id=spk %}"> Enter Student Score </a></td><tr> {% endfor %} It does work. But i need to dynamicly assign the form ID to the student id like student_id= form.instanse.pk then it complain like everse for 'gradingstudent' with arguments '()' and keyword arguments '{u'student_id': None, u'school_id': 1}' not found. when i try to assign spk = form.instanse.pk like {% with form.instance.id.to_int as spk%} <tr> <td>{{ spk }}</td> <td>{{ form.first_name }}</td> <td>{{ form.last_name}}</td> <td>{{ form.schoolName }}</td> <td><a href="{% url 'contest:gradingstudent' school_id=pk student_id=form.instance.id %}"> Enter Student Score </a></td><tr> {% endwith %} On Saturday, September 21, 2013 5:06:07 PM UTC-5, Trung Nguyen wrote: > > No this not add form and I verify it. I also use pk but it does not work > either. > > On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote: >> >> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote: >> >>> Django Version:1.5.2Exception Type:NoReverseMatchException Value: >>> >>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments >>> '{u'student_id': None, u'school_id': 1}' not found. >>> >>> Exception >>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py >>> >>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4 >>> I am new to Django. I got this error and struggle to find a solution >>> for it but no luck. Please help! >>> >>> View.py def grading_student(request, school_id=1, student_id=1): >>> urls.py >>> url(r'^(?P<school_id>\d+)/gradings/gradingstudent/(?P<student_id>\d+)/$', >>> views.grading_student, name='gradingstudent'), >>> >>> from template : >>> if I use : >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id=1 %}"> >>> Enter Student Score </a >>> It work. But when I try to replace 1 by form.instance.id i got error >>> about. >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id= >>> form.instance.id %}"> Enter Student Score </a >>> >>> if I change to this url >>> >>> a href="{% url 'contest:gradingstudent' school_id=1 student_id %}"> {{ >>> form.instance.id}} Enter Student Score </a >>> I got other error >>> >>> Don't mix *args and **kwargs in call to reverse()! >>> >>> What is the properway to do? >>> >>> >>> Thanks, >>> >>> >> The error is telling you that form.instance.id is None. Presumably this >> is because you are on an add form, and the instance hasn't been created yet >> - in which case you can't link to its contest page. >> -- >> DR. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.