How to show number of enrolled student in Course About page

Hello everyone,

In edX course About page, it can show the number of enrolled students, for example, 348, 223 already enrolled!

Image: https://i.imgur.com/ucJI52a.png
(Sorry for this inconvenience, I cannot embed an image in my post since I’m a new member)

I understand that edX uses a separate site for their commercial purpose. However, I would like to ask is there any way that I can achieve this on Open edX course About page.

I have checked the Open edX RESTful API but cannot find any endpoint that related to this problem.

Thanks in advance.

The enrollements API answers your problems halfway.

You can try this with proper authentication to fetch all enrollments in a given course

GET /api/enrollment/v1/enrollments?course_id={course_id}

Then count the results.

OR

The only ready to use code is the same as in Instructor dashboard enrollment statistics. you can summarize it in 3 lines

from common.djangoapps.student.models import CourseEnrollment

enrollments = CourseEnrollment.objects.enrollment_counts(course_key)
total_enrollments = enrollments['total']

enrollment_counts returns a dict with enrollment statistics by course mode (audit, honor, etc) + total value. You can use the code above to get the count, then integrate it in a custom view context (course_about for example) then display the count in your template.

If you look for codeless solutions I’m afraid there isn’t any

1 Like

Thank you very much for your suggestion.
I have successfully shown it on the course About page by editing lms/templates/courseware/course_about.html. The code looks like this:

<%
  # Show enrollment count on About page
  from common.djangoapps.student.models import CourseEnrollment
  enrollment_count = CourseEnrollment.objects.enrollment_counts(course.id)['total']
%>

%if enrollment_count > 1:
  <p class="number_enrolled"><span class="count">${enrollment_count}</span> ${_("already enrolled!")}</p>
%endif
1 Like