We are going to create a custom middleware to allow courses to be accessible through a custom subdomain. Each course detail URL, which looks like https://educaproject.com/course/django/, will also be accessible through the subdomain that makes use of the course slug, such as https://django.educaproject.com/. Users will be able to use the subdomain as a shortcut to access the course details. Any requests to subdomains will be redirected to each corresponding course detail URL.
Middlewares can reside anywhere within your project. However, it's recommended to create a middleware.py file in your application directory.
Create a new file inside the courses application directory and name it middleware.py. Add the ...