前提・実現したいこと
djangoでいいね機能作成中にエラーが発生しました。
django.urls.exceptions.NoReverseMatch: Reverse for 'notes.views.note_detail' not found. 'notes.views.note_detail' is not a valid view function or pattern name.
発生している問題・エラーメッセージ
Internal Server Error: /notes/detail/1/like/ Traceback (most recent call last): File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/yoshihiro/Desktop/HBGB/mysite/notes/views.py", line 212, in note_like return redirect(note_detail,id) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/shortcuts.py", line 41, in redirect return redirect_class(resolve_url(to, *args, **kwargs)) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/shortcuts.py", line 131, in resolve_url return reverse(to, args=args, kwargs=kwargs) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/urls/base.py", line 87, in reverse return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File "/Users/yoshihiro/.local/share/virtualenvs/mysite-xs0jetOT/lib/python3.8/site-packages/django/urls/resolvers.py", line 685, in _reverse_with_prefix raise NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Reverse for 'notes.views.note_detail' not found. 'notes.views.note_detail' is not a valid view function or pattern name.
該当のソースコード
urls
1from django.urls import path 2from . import views 3 4app_name = 'notes' 5 6urlpatterns = [ 7 path('detail/<int:id>/',views.note_detail,name='note_detail'), 8 path('detail/<int:id>/like/',views.note_like,name='note_like'), 9]
views
1from django.shortcuts import render, redirect 2from django.views import generic 3from .models import Note 4 5def note_detail(request,id): 6 notes = Note.objects.get(id=id) 7 return render(request, 'notes/note_detail.html', {'notes' : notes}) 8 9def note_like(request,id): 10 notes = Note.objects.get(id=id) 11 notes.like += 1 12 notes.save() 13 return redirect(note_detail,id)
note_detail.html {% block content %} <body bgcolor="#00ffff"> <div class="note"> <a href="{{ notes.file.url }}" target="_blank"><img src="{{ notes.file.url }}" width="300" alt="" border="0"></a> <h3>{{ notes.title }}</h3> <h5>投稿日{{ notes.date }}</h5> <p><a href="{% url 'notes:note_like' notes.id %}"><span id="like">{{ notes.like }}</span>いいね!</a></p> </div> </body> {% endblock %}
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。