Si Zhang
Si Zhang

Reputation: 113

Django missed slash in url

I created a url like 'api/personal/'. Everything went right when I did local test using './manage.py runserver'. But when I used factoryboy to create a client and try to get the detail by 'self.user_client.get('api/personal/')', the response showed 404 NOTFOUND because the url had changed to apipersonal/. Does anyone know why did it happen?

Upvotes: 0

Views: 63

Answers (1)

ruddra
ruddra

Reputation: 51988

Use named urls for avoiding this kind of confusions. Define the url like this:

 path('api/personal/', your_view, name='api_personal')  # added keyword argument name

and use it in the tests with reverse like this:

 self.client.get(reverse('api_personal'))

Upvotes: 1

Related Questions