简体   繁体   English

如何在Jupyter Notebook中执行Python Django runserver命令?

[英]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

  1. Install django-extension 安装django-extension
  2. Add it to your django app in setting.py INSTALLED_APPS = (..., 'django_extensions',...) 将其添加到setting.py中的django应用程序中INSTALLED_APPS = (..., 'django_extensions',...)
  3. Run 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.

相关问题 如何使通过Jupyter.kernel.execute命令执行的python命令在Jupyter Notebook的输入单元格中可见 - How to make a python command executed via Jupyter.kernel.execute command visible in an Input Cell in Jupyter Notebook 如何在 jupyter-notebook 中逐行执行代码? - How can I execute the code line by line in jupyter-notebook? 在第一个Django App教程之后,我无法执行runserver命令 - Following the First Django App tutorial and I can't execute the runserver command 如何帮助 Python 找到 Jupyter 命令“jupyter-nbconvert”,将 Jupyter Notebook 导出为 HTML? - How do I help Python find Jupyter command 'jupyter-nbconvert', to export Jupyter Notebook to HTML? 如何使用 jupyter notebook 修复 python 中的“语法错误”? - how can i fix the 'syntax error' in python using jupyter notebook? 如何在Jupyter Notebook中验证python代码? - How can I validate python code in a Jupyter Notebook? 如何在Anaconda(Jupyter笔记本)中导入python自定义类 - How can I import python custom class in Anaconda (Jupyter notebook) 如何在 Jupyter Notebook 中将 python 升级到 3.8? - How can I upgrade python to 3.8 in Jupyter Notebook? Python:我不能打电话给jupyter笔记本 - Python: I can not call jupyter notebook 无法使用 powershell 执行 jupyter notebook。 我该如何解决? - Can not execute jupyter notebook using powershell. How can I fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM