About Specific Host and Port for Live Server Test Cases

The default LiveServerTestCase runs under the localhost host and a random free port. To restrict it to a specific domain and port, overwrite the host and port attributes:

1
2
3
4
5
6
7
from django.conf import settings
from django.test import LiveServerTestCase

class RegistrationTest(LiveServerTestCase):
    host = settings.ALLOWED_HOSTS[0]
    port = 8080
    # …

Tips and Tricks Programming Testing Django 5.x Django 4.2 Django 3.2