QueraTeam / django-nextjs

Next.js integration for Django projects
MIT License
341 stars 17 forks source link

Cannot visit another endpoint #5

Closed sugamkarki closed 2 years ago

sugamkarki commented 2 years ago

I followed the steps from this tutorial. I added the created a new app called frontend and added the following codes:

# myproject/urls.py
from django.urls import include, path
urlpatterns = [
    # ...
    path("", include("frontend.urls")),
    path("", include("django_nextjs.urls")),
]
# frontend/views.py
from django_nextjs.render import render_nextjs_page_sync
def index(request):
    return render_nextjs_page_sync(request)
# frontend/urls.py
from django.urls import path
from .views import index
urlpatterns = [
    path("", index, name="index"),
]

I can now see the homepage (situated at "localhost:8000/" route) But I can't visit any other routes like "http://localhost:8000/create" which I can visit from my nextjs server "http://localhost:3000/create".

I tried adding a new route in frontend.urls.py like this

from django.urls import path
from .views import index

urlpatterns = [
    path("", index, name="index"),
    path("create/", index, name="index"),
]

but I kept getting too many redirects. Can someone show me the correct way to do this or is it even necessary to add endpoints manually?

sugamkarki commented 2 years ago

The issue was that django kept redirecting create to create/ and vice versa which caused the redirects. All I had to do was set APPEND_SLASH=False in settings.py and remove all appending slash from urls