我在測試應用程序。有必要測試處理來自地址'http://127.0.0.1:8000/api/v1/test/api_address/'的請求的方法。告訴我,請通過反向()的詳細地址給客戶從urls.py獲取路線時出錯
class MyTestCase(APITestCase):
def setUp(self):
self.message = {
'username': 'user_name',
'password': 'user_password',
}
def test_get_token(self):
response = self.client.post(reverse('api_address'), self.message)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
代碼urls.py
:
users_router = DefaultRouter()
users_router.register(r'test', TestViewSet, 'test')
users_router.register(r'test/api_address', APIAddressRequestSet, 'api_address')
當前實現,反向(「地圖地址」)不工作,一個錯誤掉落:
django.urls.exceptions.NoReverseMatch: Reverse for 'api_address' not found. 'api_address' is not a valid view function or pattern name.
如果你得到一個錯誤,你應該張貼整個事情。 –