2

I'm new to Django and Django REST.

Trying to implement recommended routing scheme using nested router for each app.

Example:

mysite.url.py:

urlpatterns = [
    url(r'^'+root_url+'/tinymce/', include('tinymce.urls')),
    url(r'^'+root_url+'/admin/', admin.site.urls),
    url(r'^'+root_url+'/swagger', swagger_schema_view),
    url(r'^'+root_url+'/', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

blog.urls.py:

from rest_framework import routers
from . import views

router = routers.DefaultRouter()
router.register(r'^/blog', views.PostViewSet)
router.register(r'^/users', views.UserViewSet)

getting exception:

django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'blog.urls' from 'C:\\Users\\user11\\PycharmProjects\\api_v2\\blog\\urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

1 Answer 1

2

Despite you use router for url mapping, you still need an urlpatterns list.

router = routers.DefaultRouter()
router.register(r'^/blog', views.PostViewSet)
router.register(r'^/users', views.UserViewSet)

urlpatterns = router.urls

Also you could omit any regexp symbols in router urls:

router.register(r'blog', views.PostViewSet)
router.register(r'users', views.UserViewSet)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.