12345678910111213141516171819202122232425 |
- from django.urls import path
- from .views import UserRegistrationView, UserProfileView # 导入我们刚创建的视图
- from rest_framework_simplejwt.views import (
- TokenObtainPairView, # SimpleJWT 自带的视图,用于登录并获取token对
- TokenRefreshView, # SimpleJWT 自带的视图,用于刷新access token
- )
- app_name = 'accounts' # 为这个应用的URL模式设置一个命名空间 (可选,但推荐)
- urlpatterns = [
- # 用户注册
- path('register/', UserRegistrationView.as_view(), name='user_register'),
-
- # 用户登录 (使用SimpleJWT提供的视图)
- # 访问此URL并POST email和password,会返回access和refresh tokens
- path('login/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
-
- # 刷新Access Token (使用SimpleJWT提供的视图)
- # 访问此URL并POST refresh token,会返回新的access token
- path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
-
- # 用户个人资料 (获取和更新)
- # 需要认证 (在视图中已设置 IsAuthenticated)
- path('profile/', UserProfileView.as_view(), name='user_profile'),
- ]
|