'Running Django on Google Colab

I was trying to run the Django on Colab, by following the instruction here, however, after the !python manage.py runserver step, I tried to

access the server using Google Colab link you printed by running the eval_js method earlier.

there is a error msg:

This page isn’t working0yztv6fmakbj-496ff2e9c6d22116-8000-colab.googleusercontent.com is currently unable to handle this request. HTTP ERROR 500

then I tried to access the link http://127.0.0.1:8000/,

and it appears error msg as follows

This page isn’t working127.0.0.1 didn’t send any data.

May I ask how to fix this? If this is not the way to run Django in Colab, what should I do? and every time I run !python manage.py runserver, it keeps executing the

Performing system checks...

Is that normal?



Solution 1:[1]

I can run it smoothly,this is my notebook https://colab.research.google.com/drive/1XcxOu_9w9Rs_m9bT3ueqeQmSctGvPjPB?usp=sharing, maybe you forgot to save the settings.py after changing ALLOWED_HOSTS, or maybe you didn't connect to the colab backend because colab disconnected the session after a few hours

sorry my english is not good

Solution 2:[2]

Everything is fine with your code but do not access the link http://127.0.0.1:8000/. Instead:

  1. Open (double-click) the settings.py in the Files section (portfolio/portfolio/settings.py) and edit the following (it will be saved automatically): ALLOWED_HOSTS = ['colab.research.google.com']

  2. I think it is optional but I would add and run !python manage.py migrate before running the server !python manage.py runserver 8000

  3. Click on the link that was printed by eval_js (print(eval_js("google.colab.kernel.proxyPort(8000)")))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akbar Prastyo Nugroho
Solution 2 DharmanBot