1

I am trying to write some notes on django with the help of org babel. Is there a way to replace a block in a file(which was not tangled with org) after I eval a certain src block?

Here's what I mean:

If my project is named ProjectA, django automatically creates the following files:

Project A
├── asgi.py
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py

Now, from within org-mode, I am creating a new app called core by executing the following:

#+begin_src shell
python manage.py startapp core
  #+end_src

It creates a new directory called "core" with some boilerplate files.

There is a section inside ProjA/settings.py where all manually created app should be registered explicitly:

  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'core',
  ]

Right now, I manually appended core to the end of the INSTALLED_APPS. But since I am creating the app from within org-babel, is there a way to register the app from within org-mode without manually going to settings.py(which is not an org tangled file) and appending core to the end? Thanks.

1
  • One way might be to write a #begin_src python block that imports the settings python module and appends core to the list INSTALLED_APPS. Regular python import issues apply, so you may need to use the :dir org header arg to run the python code from the correct directory. – Chris Clark Oct 30 '20 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.