23
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DjangoでNoReverseMatchが発生したときに最初に確認すること

Posted at

#NoReverseMatch

スクリーンショット 2017-05-11 11.43.14.png

未だにやってしまうチョボミスが発生した場合。

#原因は概ねURLディスパッチャ

myapp/urls.py
from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^', views.myapp_index, name='myapp_index'),
]

対策としては当然コードの追加。

myapp/urls.py
from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^', views.myapp_index, name='myapp_index'),
    url(r'^delete/', views.data_delete, name='data_delete'),
]

テンプレート内に挿入するこういうやりかた

{% url 'myapp:data_delete' %}

'namespace:name'

のルールになっているので、not a valid view function or pattern name.が出た場合は、urls.pyを見直してみようという話でした。

23
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?