[英]How can I execute Python Django runserver command in Jupyter Notebook?
I am new for Python,Django & Jupyter Notebook. 我是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. 我尽力从StackOverflow进行搜索和研究,并使Python Django和Jupyter Notebook一起工作。 But when I tried to execute the python manage.py runserver command in the cell and get error message such as syntax error. 但是当我尝试在单元格中执行python manage.py runserver命令并获取错误消息(例如语法错误)时。 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 我的环境是带有Python 3.5的Windows 10 Pro x64 Django 2.10 Jupyter Notebook 4.0
My guess is that your are trying to launch 'python' inside python/jupyter notebook. 我的猜测是您正在尝试在python / jupyter笔记本中启动“ python”。
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): 一般的答案是将其视为简单的shell命令(不确定它是否可以与此特定命令一起使用):
!python manage.py runserver
Debug Django in jupyter 在jupyter中调试Django
INSTALLED_APPS = (..., 'django_extensions',...)
将其添加到setting.py中的django应用程序中INSTALLED_APPS = (..., 'django_extensions',...)
python manage.py shell_plus --notebook
运行python manage.py shell_plus --notebook
You will be able to access your model from jupyter. 您将能够从jupyter访问模型。
you can find a description for an installation with win10, Python 3.5 . 您可以找到有关使用win10 Python 3.5进行安装的说明。 With python 3.6 you just start a new "python" notebook ("django-shell" is no longer there). 使用python 3.6,您只需启动一个新的“ python”笔记本(不再存在“ django-shell”)。
With win10 you need an open CMD. 使用win10,您需要一个开放的CMD。 After you have started the CMD, change to the directory where your Jupyter/Django notebook is running. 启动CMD后,转到运行Jupyter / Django笔记本的目录。 In this CMD you run: 在此CMD中,您运行:
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 也许我应该试试这个或这
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.