Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

428
Visualizações
embedding jupyter notebook/ google colab in Django app

I wanted to build a website and embed the jupyter notebook functionality of being able to create cells and run python code within it into my website

For creating a website I m using Django and I would like to embed either the google collab or jupyter notebook

By the way I have researched enough and have been stuck with the StackOverflow links where there no answer about this or the one where they want to use django in jupyter notebook

Thanks in advance for any guidance or any reference that you guys can provide.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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())

over 4 years ago · Santiago Trujillo Relatório

0

Export it first and then import it, look here for a good explanation

from google.colab import files
src = list(files.upload().values())[0]
open('mylib.py','wb').write(src)
import mylib
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda