Reputation: 1607
I seem to be getting a Caught NoReverseMatch error. I am not so sure what is causing the problem. Have a look at the full error.
Caught NoReverseMatch while rendering: Reverse for 'mmc.views.edit_note' with arguments '(1L, '')' and keyword arguments '{}' not found.
On my get_client page. I have a link to the edit note page. I am assuming the problem might be here in my template. I think the note.pk is the problem.
<a href="{% url mmc.views.edit_notes client.pk note.pk %}"> Edit Note</a>
Here is also some more information which could help. urls.py
(r'^clients/(?P<client_id>\d+)/$', views.get_client),
(r'^clients/notes/(?P<client_id>\d+)(?P<note_id>\d+)$', views.edit_notes),
views.py
@login_required
def edit_notes(request, client_id = 0, note_id = 0):
client = None
note = None
try:
client = models.Client.objects.get(pk = client_id)
note = models.Note.objects.get(pk = note_id)
except:
return HttpResponseNotFound()
if request.method == 'POST':
form = forms.NoteForm(request.POST, instance=note)
if form.is_valid():
note = form.save(commit=False)
note.user = request.user
note.client = client
note.save(True)
request.user.message_set.create(message = "Note is successfully added.")
return HttpResponse("<script language=\"javascript\" type=\"text/javascript\">window.opener.location = window.opener.location; window.close();</script>")
else:
form = forms.NoteForm(instance=note)
return render_to_response('note_form.html', {'form':form, 'client':client, 'note':note}, context_instance = RequestContext(request))
*EDIT: * Seem to have corrected most of it Here are some changes I have made.
Template
{% for note in notes %}
<a href="{% url mmc.views.edit_note client.pk note.pk %}" onclick="return showAddAnotherPopup(this);"> Edit Note</a>
{% endfor%}
urls.py
(r'^clients/notes/(?P<client_id>\d+)/(?P<note_id>\d+)/$', views.edit_note)
Now the only problem is it displays all of the links to each edit form notes for an individual client. I only want the link for the latest note and only the latest note. Is there a possible way?
Upvotes: 1
Views: 390
Reputation: 41433
(r'^clients/(?P<client_id>\d+)/$', views.get_client)
should be something like url(r'^clients/(?P<client_id>\d+)/$', views.get_client, name='MY_URL_NAME')
then called with {% url MY_URL_NAME client.pk %}
and import url
from django.conf.urls.defaults
Upvotes: 0
Reputation: 5888
The client.pk
and note.pk
are empty values, so they don't match the regex.
Upvotes: 1