Use Django in the Cloud
Instantly start a sandbox with Python's Django web framework installed.
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.
This sandbox will drop you right into a setup Django environment:
Or, you can follow along below to create your own!
# Install Django
sudo apt update
sudo apt install -y python3-django
# Create a Django project
cd /home/nt-user/workspace
django-admin startproject project .
# Run the migrations
python3 manage.py migrate
Then, you can start Django in your terminal using:
python3 manage.py runserver 0.0.0.0:8000
Note the use of the
0.0.0.0:8000
. This is required to allow remote connections, which you will technically be making to your sandbox.Now, you’ll also need to make some changes to the
project/settings.py
file. First, replace the contents of the MIDDLEWARE
list with this:MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware'
]
This removes an option added by default that prevents your webpage from being embedded, which it needs to be so the in-sandbox web browser can load it.
Then, you need add this line to the file:
ALLOWED_HOSTS = ['*']
This will allow any host to connect so the domain your sandbox is running on will be able to.
Last modified 2yr ago