How to add django app

Hi. How do I add the django_app plugin to Tutor? I have read the tutor docs but I am confused about the plugins. Is it necessary to create a django-admin directory (application named startapp django-admin) with a setup.py file to set up a tutor-myapp, right?

Hi @trungdiep! You are mistaking two different things here: I assume you want to add a Django Application to the edx-platform LMS (or CMS), right? In that case, you need to install a Python package inside the “openedx” Docker image. For that, you need to read this section of the docs: Configuration and customisation — Tutor documentation

Then, you will want to configure the LMS/CMS to actually use your Django App. For that, you will have to modify the LMS and CMS settings. The recommended approach to do that with Tutor is to create a plugin: Plugins — Tutor documentation

You will most likely have to implement the “openedx-common-settings” patch.

Does that clarify things for you?

Hi @regis, thank you for your answer.I have two questions.
when I create a plugin, How to add urls and extend app_django into INSTALL_APP ?
and when i modify code in CMS, should I install a Python package inside the “openedx” Docker image or create a plugin?

@trungdiep ,

Though i have yet to be fully successful at this I’ll share the bit of information I’ve gathered in attempting to do something similar. (@regis if i’m wrong about any of the following please correct me, i’m still trying to figure this process out myself)

TUTOR PLUGIN
Before getting started, you will need to ensure you are using the pip install version of the tutor application, and ensure it’s the version being used for the following instructions. (not the binary download, as this version will not detect custom tutor plugins) I feel this should be stated a little more “vibrantly” in the docs near the python package documentation

Once installed it will add a new executable in the python site-packages directory which can be used to run the tutor commands (mine was in /home/[USER]/.local/python3.6/lib/site-packages

  • generate a cookie-cutter plugin using the provided repository in the tutor documentation

  • to add an INSTALLED_APP you will need to add a patch to the patches directory of the cookiecutter plugin.

    • In the patches directory of the plugin, create a new file with the patch name “openedx-common-settings” (no extension or anything)
    • in that file add: INSTALLED_APPS.append('your_app_name')
  • once that’s set up you should be able to run (using the same pip version you installed tutor with)
    pip install -e ./path_to_generated_plugin/your_app_name
    if it installs correctly this plugin should now appear in tutors plugin list
    tutor plugins list ,

  • and you can enable it with: tutor plugins enable your_app_name

  • save the configurations your plugin added: tutor config save

  • run a rebuild: tutor local build openedx

PYTHON PACKAGE
to add URLS to urlpatterns you need to use edx’s django utils interface to install a django plugin which is a separate pip package installed into the openedx image.

generate a pip package and configure the setup.py to load the generated app from the above linked docs.

I’d be more specific with this but I’m still trying to get it working effectively on my end.

Once it’s set up you can add this package to tutor’s private.txt with the docs Regis linked

and rebuild the image: tutor local build openedx
which should include the package.

Note, i have been getting dependency versioning issues with this process as well as namespacing issues, but i believe this is the process. I’m still ironing out the details though.

If you have any luck with this please let me know
good luck

1 Like

hi @crivet. Thank you so much for your information. But i think this way isn’t very convenient when source code don’t complete. Is there any other way to embed the code?

I’m not 100% sure what you mean here, are you talking about code-autocompletion when editing the code?

If so, i dont believe this is possible as the source code is in the edx/edx-platform repository (or i believe Regis has his own fork of this repo tutor builds from), and this is an isolated package working along side the platform.

The only other way i can think of to add code outside of this “plugin / django-plugin” method would be to fork the base repository and make changes in there, but i dont recommend this as it would require manual updating with edx-platform releases/updates

tutor running fork of the edx-platform

As I said, i don’t recommend this as it introduces a painful process to upgrade in the future that I’m fighting with now.

@trungdiep You can use one of edx’s cookie-cutters to setup your django app so it integrates with the platform.

The cookie cutters come with most of the setup, including the integration to edx’s django utils interface as @crivet mentioned, and you can install the package in a virtual environment to get autocompletion.

1 Like