You have many options to do that:
Note:: I used "jupyter-lab" you can use "jupyter notebook"
1- The first option to redirect to "jupyter notebook"
django view.py
from django.shortcuts import redirect,HttpResponse
import subprocess
import time
def open_jupiter_notbook(request):
b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
if "9999" not in b:
a=subprocess.Popen("jupyter-lab --no-browser --port 9999".split())
start_time = time.time()
unreachable_time = 10
while "9999" not in b:
timer = time.time()
elapsed_time = timer-start_time
b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8')
if "9999" in b:
break
if elapsed_time > unreachable_time:
return HttpResponse("Unreachable")
path = b.split('\n')[1].split('::',1)[0]
#You can here add data to your path if you want to open file or anything
return redirect(path)
if you want to implement it in template instead of redirect, you can use the following code in Django template:
<iframe src="{% url 'open_jupiter_notbook' %}" width= 600px height=200px></iframe>
2- The second option:
just use jupyter notebook commands
by using this subprocess.check_output("your command".split())