Creating a Django Project

Last updated 7 months ago

How to easily get started with a Django project

To teach courses for the Django web framework, simply:

  • Select the "Python" stack

  • Add the following to your Startup Script:

apt install -y python3-django
# Create a Django project
cd /root/sandbox
django-admin startproject project .
# Run the migrations
python3 migrate

This also enables you to use the Django Model Test custom tests, for example:

from django.test import TestCase
from project.models import Animal
class AnimalTestCase(TestCase):
def setUp(self):
Animal.objects.create(name="lion", sound="roar")
Animal.objects.create(name="cat", sound="meow")
def test_animals_can_speak(self):
"""Animals that can speak are correctly identified"""
lion = Animal.objects.get(name="lion")
cat = Animal.objects.get(name="cat")
self.assertEqual(lion.speak(), 'The lion says "roar"')
self.assertEqual(cat.speak(), 'The cat says "meow"')