Search code examples
djangonext.jsdjango-urls

How to render Nextjs pages using django-nextjs on Django


I'm getting ERR_TOO_MANY_REDIRECTS everytime that I'm trying to load http://localhost:8000/about/ despite localhost:8000 loading the next index page correctly.

my next about page:


function about() {
  return <h1>about</h1>;
}

export default about;

Django Views


from django.http import HttpResponse
from django_nextjs.render import render_nextjs_page_sync

def index(request):
    return render_nextjs_page_sync(request)

def about(request):
    return render_nextjs_page_sync(request)


Django urls

from django.contrib import admin
from django.urls import include, path

from . import views


urlpatterns = [
    path('admin/', admin.site.urls),
    path("", include("django_nextjs.urls")),
    path("", views.index, name="index"),
    path("about/", views.about, name="about"),
]

https://github.com/QueraTeam/django-nextjs have been following django-nextjs offical docs. Is there something that I'm missing?


Solution

  • You may need to add APPEND_SLASH = False in your Django project's settings.py. Also, do not add / at the end of nextjs paths in urls.py.