It's not reverse('courses') alone. Probably reverse('courses-create') or
something like that.

On Tue, 26 Mar 2024 at 18:55, 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/CAFKhtoQZb1G4LDN_X-7nXJ2JMB9e%3Dz909y%3DLtNa%3D6410kmo%3DOA%40mail.gmail.com.

Reply via email to