Creating a Django Project
To teach courses for the Django web framework, simply:
    Select the Python stack
    Add the following to your Startup Script:
1
apt install -y python3-django
2
3
# Create a Django project
4
cd /home/nt-user/workspace
5
django-admin startproject project .
6
7
# Run the migrations
8
python3 manage.py migrate
Copied!
This also enables you to use the Django Model Test custom tests, for example:
1
from django.test import TestCase
2
from project.models import Animal
3
4
class AnimalTestCase(TestCase):
5
def setUp(self):
6
Animal.objects.create(name="lion", sound="roar")
7
Animal.objects.create(name="cat", sound="meow")
8
9
def test_animals_can_speak(self):
10
"""Animals that can speak are correctly identified"""
11
lion = Animal.objects.get(name="lion")
12
cat = Animal.objects.get(name="cat")
13
self.assertEqual(lion.speak(), 'The lion says "roar"')
14
self.assertEqual(cat.speak(), 'The cat says "meow"')
Copied!
Last modified 9mo ago
Copy link