0

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

楊湰陞
  • 1
  • 2
  • because it is a shell command, not python code. just start the django dev server from a different terminal. –  Dec 19 '17 at 12:26

2 Answers2

2

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.

Thomas PEDOT
  • 943
  • 1
  • 9
  • 18
  • O.K, maybe I mis-understand what Jupyter Notebook can do for me. Why I want to execute the runserver command ? because I suppose that I can debug the Django Project in the Jupyter Notebook environment. Can I ? – 楊湰陞 Dec 20 '17 at 14:14
  • Yes. You can do that. I have edited my answer to explain better. – Thomas PEDOT Dec 21 '17 at 10:47
0

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

pyano
  • 1,885
  • 10
  • 28