linux 利用 miniconda 搭建 jupyter no
2018-06-18 本文已影响0人
简达的
本篇接着上篇文章介绍如何使用 jupyter 进行 django 程序的调试和开发
安装django
#在 virtual python36 中安装 django
(base) ubuntu@ubuntu:~/my_python$ pip install django==1.11.13
新建 django project
(base) ubuntu@ubuntu:~/my_python$ django-admin startproject application
新建 app ,顺便做 migrate,创建一个superuser
(base) ubuntu@ubuntu:~/my_python/application$ python manage.py startapp web
(base) ubuntu@ubuntu:~/my_python/application$ python manage.py migrate
(base) ubuntu@ubuntu:~/my_python/application$ python manage.py createsuperuser --username admin
安装 django-extensions
(base) ubuntu@ubuntu:~/my_python/application$ pip install django-extensions
settings.py 添加 django_extensions 及 NOTEBOOK_ARGUMENTS
INSTALLED_APPS += ['django_extensions']
NOTEBOOK_ARGUMENTS = [
'--ip', '0.0.0.0',
'--port', '8889',
]
启动
(base) ubuntu@ubuntu:~/my_python/jianda$ python manage.py shell_plus --notebook
这就进入项目目录了(对原生目录稍有改动),一般用 Django Shell-Plus 新建文件,如图
![](https://img.haomeiwen.com/i11526590/d61734ffe6e151e6.png)
进入 jupyter_notebook 新建文件 demo_1.ipynb
在开头运行如下代码引入 django settings
import os, sys
MYPROJECT = os.getcwd()[:os.getcwd().find('/jupyter_notebook')]
sys.path.insert(0, MYPROJECT)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.py")
import django
django.setup()
![](https://img.haomeiwen.com/i11526590/09e632570deabeca.png)
接着就能使用项目里的文件和 ORM 了,如使用 User
![](https://img.haomeiwen.com/i11526590/23b25897ec3529f7.png)
顺便推荐一个超好用的 chrome 插件 眼睛护航
![](https://img.haomeiwen.com/i11526590/18cd2083bae15460.png)
夜间模式开启后是这样的:
![](https://img.haomeiwen.com/i11526590/2e58842cf4637f2d.png)