1

I need this feature

Users can create an account in my webapp and have their profile page under:

username.mydomain.com

(subdomain).

How can I do something like this? Where do I start?

Alvaro
  • 11,797
  • 9
  • 40
  • 57
user3146138
  • 41
  • 1
  • 6
  • Are you asking how to design your own user model or how to redirect the urls like in the example? – yuvi Jan 10 '14 at 13:04
  • @yuvi I ask about everything. I don't understand how to begin to design and create such a function (and how to operate on subdomains). How it should work. – user3146138 Jan 10 '14 at 13:07
  • Why do you want to do this? I don't think it is easy at all! Why not use a domain/user url? – Alvaro Jan 10 '14 at 13:28

1 Answers1

0

I wont write it all for you but here is how I've done it before:

  1. DNS must forward all subdomains to your service (A record *.yourdomain.com -> your IP address);
  2. If you've deployed with Nginx you can use the REGEX URL selector to capture the subdomain (their username) and pass this to your service as a url path (so username.yourdomain.com becomes yourdomain.com/username without displaying this to the user). This SO question - Nginx convert subdomain to path component without redirect - should help you.
  3. Now it's easy to use Djangos built in URLs to take that username and return the correct profile page.

Edit 1:

Bonus

By default this will create a 404 - Not found error message if a username is entered that doesn't have their own account. If you use Djangos urls (something like /users/username/) you can return a custom User not found or similar error message to make the user experience a bit smoother.

Community
  • 1
  • 1
Ewan
  • 14,592
  • 6
  • 48
  • 62