質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

1044閲覧

NoReverseMatchで困っています

yoshihiro27

総合スコア1

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/04/28 10:19

前提・実現したいこと

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/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

return redirect('notes:note_detail' notes.id)で解決しました

投稿2021/05/10 02:21

yoshihiro27

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

return redirect(note_detail, notes.id)で、どうでしょうか?

投稿2021/04/29 15:32

shuring

総合スコア19

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yoshihiro27

2021/04/30 09:21

質問と同じエラーが発生して何も変わりませんでした
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問