Convenient application for the implementation of subdomains in Django - django-hosts
django-hosts is a useful application from the wonderful Jannis Leidel , which is part of Django core-developers and oversees a large number of Django-projects. Documentation can be found on readthedocs . Installation example:
Install: pip install django-hosts
Add 'django_hosts' to INSTALLED_APPS
Add 'django_hosts.middleware.HostsMiddleware' to MIDDLEWARE_CLASSES
Create a file in the project directory. Name it, for example, hosts.py.
In accordance with the hosts.py file, we will have 3 hosts: api.site.com, news.site.com, forum.site.com.
In settings.py add: ROOT_HOSTCONF = 'projectname.hosts'
Do not forget about setting up a wildcard subdomain (Although not necessarily a wildcard - it’s enough to write the necessary ones. Well, I think everyone knows how to do all this). Upd: Today I received a message from Jannis Leidel, in which he said that django-hosts is on his list of applications that he wants to offer to include in Django. In version 1.3 already added its django-staticfiles as django.contrib.staticfiles. It would also be great if Django-compressor was added to Django.