楊湰陞
楊湰陞

Reputation: 1

How can I execute Python Django runserver command in Jupyter Notebook?

I am new for Python,Django & Jupyter Notebook. And I tried my best to search and study from StackOverflow and get the Python Django and Jupyter Notebook work together. But when I tried to execute the python manage.py runserver command in the cell and get error message such as syntax error. So can anyone help me to solve this problem. My environment is Windows 10 Pro x64 with Python 3.5 Django 2.10 Jupyter Notebook 4.0

Upvotes: 0

Views: 2407

Answers (2)

Thomas PEDOT
Thomas PEDOT

Reputation: 993

My guess is that your are trying to launch 'python' inside python/jupyter notebook.

python manage.py runserver

A general answer is to see it as a simple shell commands (not sure it can work with this particular command):

!python manage.py runserver

Debug Django in jupyter

  1. Install django-extension
  2. Add it to your django app in setting.py INSTALLED_APPS = (..., 'django_extensions',...)
  3. Run python manage.py shell_plus --notebook

You will be able to access your model from jupyter.

Upvotes: 2

pyano
pyano

Reputation: 1988

you can find a description for an installation with win10, Python 3.5. With python 3.6 you just start a new "python" notebook ("django-shell" is no longer there).

With win10 you need an open CMD. After you have started the CMD, change to the directory where your Jupyter/Django notebook is running. In this CMD you run:

python manage.py runserver

To be honest: with that I can run my example given there:

from django.template import Template, Context

template = Template('The name of this project is {{ projectName }}')
context = Context({'projectName': 'MyJypyterDjangoSite'})
template.render(context)

but I still have troubles myself when I want to work with templates-files to be included. Perhaps I should try this or this

Upvotes: 0

Related Questions