Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: Can not get API up without using cms.urls (Headless only mode) #8

Open
metaforx opened this issue Sep 13, 2024 · 4 comments
Open

Comments

@metaforx
Copy link

metaforx commented Sep 13, 2024

Django 5.0.6
Django CMS: 4.1.2
Default is English, not multi-lingual or multi-site setup

If I run headless only, I get API Overview for languages, but not for pages.

HEADLESS:
If I disable cms.urls i loose frontend edit capabilities because if I have to disable {% cms_toolbar %} in templates. It might be related.

Initially, I also got this error: Reverse for 'pages-root' not found. 'pages-root' is not a valid view function or pattern name. When creating a website for the first time.

API Return:

[
    {
        "code": "en",
        "name": "English",
        "public": true,
        "redirect_on_fallback": true,
        "hide_untranslated": true,
        "fallbacks": [],
        "pages": "http://localhost:8080/api/en/pages"
    }
]
"pages": "http://localhost:8080/api/en/pages"
NoReverseMatch at /api/en/pages
Reverse for 'pages-root' not found. 'pages-root' is not a valid view function or pattern name.

HYBRID: SOLVED (order of API in urls.py)

#djangocms_rest/urls.py
path("<slug:language>/pages/<path:path>/", views.PageDetail.as_view(), name="cms-page-detail"),
"path": "http://localhost:8080/api/en/pages/test/",
#error  cms.views.details is hjacking api requests and returns 404

The expected result would be an API return for the test page, right?
I get standard 404 from django.

@metaforx
Copy link
Author

Gotcha: For hybrid mode, I have to make sure to use api first in urls:
This solves the issue in Hybrid mode

path('api/', include('djangocms_rest.urls')),
path("", include("cms.urls")),

@metaforx metaforx changed the title error: Can not get API up without using cms.urls , but with cms.urls i do only get root API level error: Can not get API up without using cms.urls (Headless only mode) Sep 13, 2024
@fsbraun
Copy link
Owner

fsbraun commented Sep 13, 2024

What's your urls.py for fully headless?

@metaforx
Copy link
Author

from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include
from debug_toolbar.toolbar import debug_toolbar_urls

urlpatterns = ([
    path('admin/', admin.site.urls),
    path('api/', include('djangocms_rest.urls')),
    # path("", include("cms.urls")),
])

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

http://127.0.0.1:8080/api/en/pages
Reverse for 'pages-root' not found. 'pages-root' is not a valid view function or pattern name.

http://127.0.0.1:8080/api/

[
    {
        "code": "en",
        "name": "English",
        "public": true,
        "redirect_on_fallback": true,
        "hide_untranslated": true,
        "fallbacks": [],
        "pages": "http://127.0.0.1:8080/api/en/pages"
    }
]

@fsbraun
Copy link
Owner

fsbraun commented Sep 13, 2024

Ah, ok. This should work on django CMS 4.2+, on 4.1.x you'd have to have the CMS urls exposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants