Check your url. This error usually show up when there's no url with the name provided for the reverse function
On Tue, Mar 26, 2024, 11:55 AM Filbert <timn...@gmail.com> wrote: > Consider this what seems to be a simple Django/DRF API which works: > > class CourseViewSet(viewsets.ModelViewSet): > queryset = Course.objects.all() > serializer_class = CourseSerializer > > router = DefaultRouter() > router.register(r'courses', CourseViewSet) > > urlpatterns = [ > path('', include(router.urls)), > ] > > POST to: *http://localhost:9000/courses/ <http://localhost:9000/courses/>* > works from cURL > > But this code: > class CourseAPITest(TestCase): > def setUp(self): > self.client = APIClient() > self.course_data = {'description': 'course number 1', 'name': 'intro > to something'} > self.response = self.client.post(reverse('courses'), > self.course_data, > format='json') > > Gives me the error: > > *django.urls.exceptions.NoReverseMatch: Reverse for 'courses' not found. > 'courses' is not a valid view function or pattern name.* > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/21615aab-a01a-4a1c-bc79-ed88908cafbbn%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/21615aab-a01a-4a1c-bc79-ed88908cafbbn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACABt6T%2BpX5_OnWh_mmBvtwHUV%3DisZPsJdmS%2Bes2aZpOssWPhQ%40mail.gmail.com.