Forums

Using Jupyter notebook to debug with django

Hey!

I have a Django app, and it's working well in regular python-files to get data from databases by importing modules. However, I want to be able to do this interactively through an iPython notebook (it's really hard to do this on the shell because I have hundreds of lines to paste) and I can't import the databases there.

I've read many posts regarding problems with Django/pythonanywhere/notebooks but none seems to fit. I just want to be able to import:

from tracking.models import Page

in the iPython notebook, which I have in another app, but I get an error:

ImportError: No module named tracking.models

The structure is like this:

  • django:
  • front_end:
    • api:
      • many files, including the desired notebook
  • src/
    • some files
  • static/
    • some files
  • tracking/
    • generated Django files, including models.py, where we create our models, among others Page

Is there any good way to interact nicely with Django inside of the notebook in pythonanywhere?

Thank you so much!

interesting. the traditional way of doing this would probably be to have scripts instead of pasting in line by line, and doing it interactively from the shell by importing those scripts.

try playing around with a sys.path.append('your-django-folder') before trying to import anything.