Skip to main content

Instances

A simple way of allowing subdomains to be served by the same project, and associating objects with particular subdomains.

Installation

  1. By default, it will work if you use 127.0.0.1.nip.io (a domain that points to localhost) on port 80. To use a different base domain/port, set the BASE_HOST and/or BASE_PORT variables.

  2. Add instances to your INSTALLED_APPS and migrate to get the Instance database table.

  3. Add Instance objects, with the label being the subdomain you wish to use. Optionally, associate users with these instances.

  4. Add instances.middleware.MultiInstanceMiddleware to your middleware; it must come after AuthenticationMiddleware. Now if you go to <subdomain>.<BASE_HOST>, request.instance will be set to the matching Instance object. If there’s a subdomain given but no match, it will redirect to BASE_HOST.

Requests to a subdomain will use your ROOT_URLCONF file; requests to the BASE_HOST will use ROOT_URLCONF_HOST or instances.urls by default (which just has one page that lists all instances)..

Instance edit form

In your ROOT_URLCONF, use a line like the following to have a page for editing the title and description of an instance:

url(r’^instance/edit$’, InstanceUpdate.as_view(), name=’instance-edit’)

Associating models

To have a model’s objects be associated with an instance, mix in InstanceMixin, and if you have a custom manager make it a subclass of InstanceManager. This adds an instance field, and provides a for_instance manager method to return all the objects in the given instance.

Mix in InstanceViewMixin to any display class-based view to restrict the default queryset to the request’s instance. Add InstanceFormMixin to any create/update view to store the current instance upon save, and allow editing only by those users associated with the instance. Remember to exclude instance from any model form, as it won’t be seen.

Running tests

pip install .
python runtests.py

Metadata

Release files for django-subdomain-instances 3.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-subdomain-instances 3.0.2
File Size Uploaded
django-subdomain-instances-3.0.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-subdomain-instances 3.0.2
File Interpreter ABI Platform
django_subdomain_instances-3.0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 23.1 kB

Release files / django-subdomain-instances-3.0.2.tar.gz

Download URL django-subdomain-instances-3.0.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
88c50d37745c9f1ebd561a3892d9bd6c4e2e27fe6a702d36409205025337a59c
BLAKE2b-256 checksum
How to use checksums
3e7443025b03224fbb6beac948f6adcbbc8b1953eea03fe6dfa04af5f6fdc1c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Release files / django_subdomain_instances-3.0.2-py2.py3-none-any.whl

Download URL django_subdomain_instances-3.0.2-py2.py3-none-any.whl
Size 13.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
beb3df026cdf0d9a636688d6f193301f6f079d0f5a7dcf7359bdb18f41f86dd2
BLAKE2b-256 checksum
How to use checksums
1f537a5ee6ca33890b25ba3ef9b0920b4894f0bbc1ae2bd05932f7f7dde9d6e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Release history Release notifications | RSS feed

This release

3.0.2 This release

2 release files

3.0.1

2 release files

3.0

2 release files

2.0

2 release files

1.0

2 release files

0.10.2

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page