djoser_postman_collection.json
使用方法
将上述 JSON 内容保存到一个文件(如 djoser_postman_collection.json)。
打开 Postman,点击 “导入” 按钮,选择文件,并导入此文件。
设置 Postman 环境变量:
{{base_url}}:设置为你的 Django 服务器地址(例如,http://localhost:8000)。
{{user_token}}:在用户登录成功后,将获得的 Token 设置到此变量,便于调用需要认证的 API。
这样,你就可以直接在 Postman 中测试 Djoser 提供的 API
{
"info": {
"_postman_id": "cb99034b-1ee2-4721-9e06-85f18af0806f",
"name": "Djoser API Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "39382064"
},
"item": [
{
"name": "User Registration",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"testuser\",\n \"password\": \"testpassword\",\n \"email\": \"test@example.com\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/users/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"users",
""
]
}
},
"response": []
},
{
"name": "User Login",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"testuser\",\n \"password\": \"testpassword\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/token/login/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"token",
"login",
""
]
}
},
"response": []
},
{
"name": "User Logout",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Token {{user_token}}",
"type": "text"
}
],
"url": {
"raw": "{{base_url}}/api/auth/token/logout/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"token",
"logout",
""
]
}
},
"response": []
},
{
"name": "Password Reset",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"test@example.com\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/users/reset_password/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"users",
"reset_password",
""
]
}
},
"response": []
},
{
"name": "Password Reset Confirmation",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"uid\": \"user_id\",\n \"token\": \"reset_token\",\n \"new_password\": \"newpassword\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/users/reset_password_confirm/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"users",
"reset_password_confirm",
""
]
}
},
"response": []
},
{
"name": "User Details",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Token {{user_token}}",
"type": "text"
},
{
"key": "",
"value": "",
"type": "text",
"disabled": true
}
],
"url": {
"raw": "{{base_url}}/api/auth/users/me/",
"host": [
"{{base_url}}"
],
"path": [
"api",
"auth",
"users",
"me",
""
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "base_url",
"value": "http://localhost:8000",
"type": "string"
},
{
"key": "user_token",
"value": "624d0a976e0b47978abbe4eb9e307bb97712ccaf",
"type": "string"
}
]
}