TemplateDoesNotExist exception after installing an `openedx.course_tab` module

Hello everyone,

There is obviously some difference between installing an XBlock or module using these methods listed below. The first method works, but the second method generates a TemplateDoesNotExist exception when accessing the openedx.course_tab module. Iā€™m hoping that someone can shed some light on this for me. :slight_smile:

Question: What is the correct method of setting or referencing the templates directory in an openedx.course_tab module so that they are found?

  1. Cloning the rocketchat-tab module first and then adding the path to the requirements/private.txt file works.

    cd $(tutor config printroot)/env/build/openedx/requirements
    
    # Clone and then install (works as expected)
    git clone https://github.com/tony-h/rocketchat-tab.git
    echo "-e ./rocketchat-tab/" >> private.txt
    
  2. However, installing it by adding git+https://repo-path.git to the requirements/private.txt generates a TemplateDoesNotExist exception when the new tab is opened.

    cd $(tutor config printroot)/env/build/openedx/requirements
    
    # Installs, but can't find the template
    echo "git+https://github.com/tony-h/rocketchat-tab.git" >> private.txt
    

The stack trace:

lms_1                        | 2022-08-22 05:13:46,277 ERROR 49 [django.request] [user 34] [ip 91.197.235.251] log.py:224 - Internal Server Error: /courses/course-v1:CS+CC+2022/chat
lms_1                        | Traceback (most recent call last):
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
lms_1                        |     response = get_response(request)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
lms_1                        |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
lms_1                        |   File "/opt/pyenv/versions/3.8.12/lib/python3.8/contextlib.py", line 75, in inner
lms_1                        |     return func(*args, **kwds)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
lms_1                        |     return self.dispatch(request, *args, **kwargs)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
lms_1                        |     return handler(request, *args, **kwargs)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/web_fragments/views.py", line 23, in get
lms_1                        |     fragment = self.render_to_fragment(request, **kwargs)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/rocketchat_tab/views.py", line 83, in render_to_fragment
lms_1                        |     html = render_to_string(
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/template/loader.py", line 61, in render_to_string
lms_1                        |     template = get_template(template_name, using=using)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/template/loader.py", line 19, in get_template
lms_1                        |     raise TemplateDoesNotExist(template_name, chain=chain)
lms_1                        | django.template.exceptions.TemplateDoesNotExist: rocket_chat/rocket_chat.html

I can confirm that the template or static directories do not exist in the site-packages directory after installation. Where did they go? :thinking:find ~ -type f -name "rocket_chat.html" returns an empty result.

app@11afc8e1bf60:~/venv/lib/python3.8/site-packages/rocketchat_tab$ ls -lh
total 64K
-rw-r--r-- 1 app app   89 Aug 22 16:21 admin.py
-rw-r--r-- 1 app app 5.6K Aug 22 16:21 ApiRequest.py
-rw-r--r-- 1 app app  850 Aug 22 16:21 apps.py
-rw-r--r-- 1 app app    0 Aug 22 16:21 __init__.py
drwxr-xr-x 3 app app 4.0K Aug 22 16:21 migrations
-rw-r--r-- 1 app app   83 Aug 22 16:21 models.py
-rw-r--r-- 1 app app  773 Aug 22 16:21 plugins.py
drwxr-xr-x 2 app app 4.0K Aug 22 16:21 __pycache__
-rw-r--r-- 1 app app  772 Aug 22 16:21 RocketChatError.py
-rw-r--r-- 1 app app  11K Aug 22 16:21 RocketChat.py
drwxr-xr-x 3 app app 4.0K Aug 22 16:21 settings
-rw-r--r-- 1 app app  315 Aug 22 16:21 urls.py
-rw-r--r-- 1 app app 4.2K Aug 22 16:21 views.py
app@11afc8e1bf60:~/venv/lib/python3.8/site-packages/rocketchat_tab$

Any ideas on how to set the reference to the templates and static files so that Open edX can locate them? :slight_smile:

Many thanks

By default, your setup.py file will only include Python files. Try adding a MANIFEST.in file at the top level, like edx-ora2 does, and specifying the other file patterns you want included there.

1 Like

Thanks, @dave! This information was very helpful! :pray: Adding the MANIFEST.in file was half the problem. I also had to set the include_package_data=True flag in setuptools.setup( ... ), as is also set in the edx-ora2 XBlock.

Reference site: Data Files Support - setuptools 65.2.0.post20220821 documentation

1 Like