user3084860
user3084860

Reputation: 461

Django Let Users Add Custom Domains

I would like to allow users to map their domain to their page in my Django app. So if their page is at: user.mydomain.com, I'd like them to be able to map their domain to the url so it becomes: usersdomain.com .

I found this answer which gave me an idea of how to setup subdomains:

If you control the nameserver for the domain and have access to the RNDC Key, you can use the post-signup view/signal to squirt out a cname to your DNS server that will resove username.yoursite.com to yoursite.com. Make sure apache is set up to recieve a wildcard virtualhost to the correct app, and then use a custom middleware to read request.META['SERVER_NAME'].lsplit('.')[0] to see what the subdomain is. You can then use this information in your views to differentiate user subdomains.

But I'm at a loss as to how to let users point their domains to my subdomain.

Upvotes: 5

Views: 2786

Answers (1)

metahamza
metahamza

Reputation: 1455

How I would approach this is first, instruct your users to set up the appropriate DNS record to point their domain to yours (likely a CNAME).

Then you'll need to set the ALLOWED_HOSTS setting in your settings.py to a wildcard (*), which is supported. The thing to be aware of is this configuration opens a security vulnerability, so you'll want to implement your own host validation, recommended at the middleware level by Django.

Then you'll have to modify whatever technique you're using to display a user's page. Instead of matching the subdomain, match the entire domain.

Upvotes: 2

Related Questions