Python Question

Django 404 error with TemplateView

I have urls in app and when I go to article-report url I see django error page
with urls for article, but there is no url for article-report.

from rest_framework import routers
from main.views import (ArticleViewSet)
from django.views.generic import TemplateView

router = routers.DefaultRouter()
router.register(r'article-report', TemplateView.as_view(template_name = 'report.html'),'report')
router.register(r'article', ArticleViewSet)
urlpatterns = router.urls

part of

'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'context_processors': [

The terminal receives a message

[26/Jul/2017 14:22:14] "GET /article-report HTTP/1.1" 404 5777

Pycharm underlines django,TemplateView and rest_framework in import lines.
But in other examples It doesnt matter

Answer Source

You should include the TemplateView as a url() in urlpatterns, instead of trying to register it with the router.

router = routers.DefaultRouter()
router.register(r'article', ArticleViewSet)

urlpatterns = [
    url(r'article-report', TemplateView.as_view(template_name='report.html'), name='report')  # note kwarg name='report' instead of arg 'report'

urlpatterns += router.urls
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download