Hi
I am using Django Rest Framework for my application. I have set up everything and the login works and I get the login page. But if I go to the register page I get page not found, which I don’t understand because the path is set up correctly.
Here is my main project’s urls.py:
from django.contrib import admin
from django.urls import path, include
from .views import home_view, api_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', home_view),
path('account/', include('rest_framework.urls')),
path('companies/', include('businesses.urls')),
path('page/', include('pages.urls')),
]
and here is my accounts urls.py
from django.urls import path
from .views import RegisterView, LoginView
from knox import views as knox_views
urlpatterns = [
path('register/', RegisterView.as_view(), name='register'),
path('login/', LoginView.as_view(), name='login'),
path('logout/', knox_views.LogoutView.as_view(), name='logout'),
path('logoutall/', knox_views.LogoutAllView.as_view(), name='logoutall'),
]
and this is what the page is showing:
Page not found
Request Method: GET
Request URL: http://127.0.0.1:8000/account/register/
Using the URLconf defined in sobusnet.urls, Django tried these URL patterns, in this order:
- admin/
- account/ ^login/$ [name=‘login’]
- account/ ^logout/$ [name=‘logout’]
- companies/
- page/
The current path, account/register/, didn’t match any of these.
I have a couple of questions please:
- Why on the browser on the page not found page is number 2. in the URL patterns empty?
- Why is it using the GET method when in the view I only have a post method?
- Why is the register path not found but the login path is?
- What is the ^ for in the account/login and logout paths?
Here is my register view:
class RegisterView(GenericAPIView):
serializer_class = RegisterSerializer
def post(self, request):
serializer=RegisterSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer._data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)