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:
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
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.