Add a Foo application for the open edx platform - django

Keywords: OpenEdX - Virtual Machines - How to - Other
Description:
# How to access Django and create new apps for edx backend ?

A tutorial would be much much appreciated by the community! Documentation of Edx is overwelming (let alone that working with a VM has its own challenge)

Id like to apply for a job that ask understanding of Edx and Django, and struggle to access edx because I can only use VM and .. well, it is rather complex:
please help me understand how to address a first simple task.

Create a new app (django-admin) and model , modify template in front end

I can create applications for django project, I can create a foo app to display last entry on an html template.

I want to replicate the same in open edx, using the VM as a sand-box.

I tried:

  • locate /apps/eds/edx-platforms

I see there is manage.py but not a django-admin.py

I could not figure out where it is, I read in the git manage.py will delegate commands to django-admin, anyway.

So I try to crate an app, like:

python3 manage.py startapp /features/myapp (yes, on open edx guidelines I read it is adviced to place apps in /features folder )

But:

from safe_lxml import defuse_xml_libs
importError: No module named safe_lxml

I thought it could be that I gotta run in virtual enviroments, so I looked around documentation could not find.

I eventually found the directory venvsin parent folder, tried to launch :

source venvs/edxapp/bin/activate`
then try again :

python3 manage.py startapp /features/myapp

same error.

Is it an error really due to a missing library, or is it something higher level, I suspect, for I am not following the right procedure to create new apps for a django backend of openedx?

https://edx.readthedocs.io/projects/edx-developer-guide/en/latest/architecture.html

did not help me much...

Could you kindly show a foo procedure to create a foo app in django for open edx,
to understand the differences to do the same VS a "normal" django project ?

I am struggling even to find the right folders ( also because at the moment I m having other issues to working smoothly with the VM interface ) .

Thank you for your help.

Hi @gg4u,
This issue is related to this other one https://community.bitnami.com/t/problems-with-open-edx-stack-config/31916/5, can you take a look to see if doing that it works?
You need to use the scripts under the edx directory because it load some env vars needed.

safe_lxml. is a local library
you should run:
make requirements

Thank you @miguelaeh.

I tried https://community.bitnami.com/t/problems-with-open-edx-stack-config/31916/3?u=gg4u

Could not see any edx user, unable to initialize policy plugin.

I tried:
https://community.bitnami.com/t/problems-with-open-edx-stack-config/31916/9?u=gg4u

I don't have a /bin/ folder in /edx-platform/, but parent folder:

Tried to run python from there, but still error: I think because python is not loaded from a virtual environment of edx.

@talha.sdk thank you for your help.

Tried to make requiriments, system seems in halt, nothing happening after a while.

HAd a look at description .txt in it, but could not figure out a solution.

Any tutorial to create a foo / mockup application in django for open edx ?

Hi @gg4u,
Thanks for checking the other thread, let's continue with your issue then.
Regarding the bin folder containing the django-admin.py you can find it at

/opt/bitnami/apps/edx/venvs/edxapp/lib/python2.7/site-packages/django/bin/django-admin.py

I am able to reproduce you issue just executing:

 cd apps/edx/edx-platform/
 python3 manage.py startapp testApp

Remeber to load the edx virtualenv. To do that execute from /opt/bitnami/apps/edx/venvs/edxapp:

. ./bin/activate

I can see that the module is installed:

(edxapp) bitnami@ip-172-31-6-33:/opt/bitnami/apps/edx/edx-platform$ pip list | grep lxml
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
lxml                          3.8.0
safe-lxml                     1.0                   /opt/bitnami/apps/edx/edx-platform/common/lib/safe_lxml

I am going to forward the issue to other team that will check the issue deeper.

hi @miguelaeh ,

I confirm issue.
steps to reproduce:

  1. activated

source ./opt/bitnami/apps/edx/venvs/edxapp/bin/activate

(please note there are 2 different virtual environments in venvs folder)

2.

python3 manage.py startapp testApp in

/home/bitnami/edx-platform/

Hi, @gg4u.

Please note that this stack uses Python 2 instead of Python 3. Therefore, you should use python instead of python3 to run your commands.

Regards,
Alejandro

thank you @amoreno, but did not solve the issue.

Hi, @gg4u.

What's exactly the problem you are having with django-admin? It is working for me:

Just load the environment and the django-admin script should be in the PATH.

Regards,
Alejandro

@amoreno ok, problem solved, but if you can also share a tutorial, it will be much useful.

About my problem: I think it was probably due to confusion and understanding how edx is organised on the VM.
Initially I located home/bitnami/apps/edx/edx-platform but could not see django-admin.py in the folder. The only python file there is manage.py, so I looked at it in the git, I read lines it would delegate commads to django-admin, so I tried to pass startapp command to manage.py, which was causing error.

Actually, after having found and activated the virtual environment, I confirm it will create a testApp.

However, please note I don't have an edx-platform folder in /home/bitnami/, I have it in the folder I mentioned above.

This thread is about adding a foo application on the open edx platform.

I could add a foo application in django CMS.

Could you please suggest where to organise folders (I think a new application should be created in the edx-platform folder) and show how to create a foo application, so that I could familiarise between the differences with django CMS and open-edx ?

As example, I wish to create a model to add new users, and display last user on the front-end.
I could it in CMS, I'd like to understand how to in open-edx, so that I could learn by practice where are the things VS CMS.

Not asking to code anything here, just to debrief about how to, good practices and differences to keep in mind.

Hi, @gg4u.

Open Edx is just an application built on top on Django. When you run the django-admin script to create an application, you are doing just that: creating a new Django application.

If you want to create a Django application, then I think the Bitnami Django Stack would be more suited to your needs.

Regards,
Alejandro

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.