Where to set up subdomain routing? Front-end (React) or Django (Backend)?

I'm currently building a multi-tenant web application using Django and React. Right now, each user's page is available at a URL like https://mywebsite.com/. However, I want to change this so that each user has their own subdomain, for example: https://username.mywebsite.com.

My setup is as follows: I'm using React for the frontend and Django (with Django REST Framework) for the backend. Both are running on the same server. I’m serving the React build/ folder directly through Django by connecting it in the Django urls.py file.

What I want to achieve is true subdomain-based routing so that each user or tenant can have their own subdomain. I’m not sure exactly what changes are needed to make this work, especially across the different layers of the stack. Specifically, I’m looking to understand what needs to be done at the DNS or Nginx/server configuration level, what changes I need to make in Django to detect and handle subdomains, and whether any updates are needed on the React side. I’m also wondering whether there’s a way to test this kind of subdomain setup locally during development (like on localhost).

Finally, I'd like to know how to extract the subdomain (which would be the username or tenant identifier) in Django and route the request accordingly.

If anyone can guide me or point me in the right direction, that would be a huge help.

Subdomain resolutions are a matter for the DNS, not the backend/frontend.

But you can add a *.yourdomain.com and handle the logic server-side

In that case, your question was already answered here Using subdomains in django

Вернуться на верх