2011-06-28 7 views
1

私はCaught NoReverseMatchエラーが発生しているようです。私はその問題を引き起こしていることが分かりません。完全なエラーを見てください。Django:レンダリングエラー中にNoReverseMatchを取得

Caught NoReverseMatch while rendering: Reverse for 'mmc.views.edit_note' with arguments '(1L, '')' and keyword arguments '{}' not found. 

私のget_clientページにあります。編集ノートページへのリンクがあります。私は問題がテンプレート内にあるかもしれないと仮定しています。私はnote.pkが問題だと思います。

<a href="{% url mmc.views.edit_notes client.pk note.pk %}"> Edit Note</a> 

さらに詳しい情報もあります。 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:*は、ここでのほとんどを修正しているように見えるが、私が作ったいくつかの変更です。

テンプレート

{% 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) 

今、唯一の問題は、それは個々のクライアントのために、各編集フォームノートへのリンクがすべて表示されています。最新のメモと最新のメモのみのリンクが必要です。可能な方法はありますか?

答えて

0

(r'^clients/(?P<client_id>\d+)/$', views.get_client)は、{% url MY_URL_NAME client.pk %}

と呼ばurl(r'^clients/(?P<client_id>\d+)/$', views.get_client, name='MY_URL_NAME')ようなものになるとdjango.conf.urls.defaults

1

client.pknote.pkは空の値なので、正規表現と一致しません。私はちょうど `持っ Edit Note`私が空でない値を取得しない場合は

+0

からurlをインポートする必要があります – Shehzad009

関連する問題