如何通过 urls.py 使用 DRF 引发 NotFound 异常

How to raise the NotFound exception with DRF via the urls.py

任何人都可以确认如何通过 urls.py 使用 DRF 引发 NotFound 异常吗?

urlpatterns = [
    url(r'^blog/$', views.page),
    url(r'^$, <?????>),
]

谢谢

你应该在视图中提出它

urls.py:

urlpatterns = [
    url(r'^blog/$', views.page),
    url(r'^$', views.not_found),
]

views.py:

from rest_framework.exceptions import NotFound
from rest_framework.decorators import api_view

@api_view()
def not_found(request):
    raise NotFound('Not Found!')