Dynamic switching of the settings.SIDE_ID for a Django Project
Project description
Django Agile Sites (django_agilesites)
This provides django the ability of dynamic switching of the settings.SIDE_ID. This allows you to then alter the template paths based on the SITE_ID by referencing settings.SITE_FOLDERS.
The way this works is first by dynamically setting (thread-safe) the settings.SITE_ID based on the request.get_host() (which is based in part on request.META['HTTP_HOST']). Once the SITE_ID is established, then it uses that to dynamically look up any template path folder structure you define.
Example / Setup
Lets assume we want to have all traffic going to //beta.foo.com to use our new templates tree
called 'beta' for a new template app_detail.html
. This app will allows you to place the
following templates folder structure in your app to achieve this:
app/
templates/
app/
app_detail.html
app_list.html
beta/
app_detail.html
We need to reference the two sites in question - so in the sites app assume the following. SITE_ID: 1 domain: foo.com SITE_ID: 2 domain: beta.foo.com
Now to enable this to work you need to do the following:
-
Add the
django_agilesites
to the settings.INSTALLED_APPS -
Add the
django_agilesites.loaders.AgileSiteAppDirectoriesFinder
to the settings.TEMPLATE_LOADERS. I put it first. -
Add the
django_agilesites.middleware.AgileSitesMiddleware'
to the settings.MIDDLEWARE_CLASSES -
Add the following settings to reference the folder beta.
SITE_FOLDERS = { 2: 'beta', }
That's it.
Now when you go to //beta.foo.com/app/detail you will use the template in the beta tree and when you go to the list view on beta it will refer to the parent app_list.html.
Notes:
-
You do NOT need to reference the SITE_ID 1 as there isn't a path change for that.
-
You don't have to put every url. We also support the notion of aliases through the use of settings.SITE_ALIASES dictionary. This will force //beta.bar.com to also use the beta templates.
SITE_ALIASES = { 'beta.bar.com': 2, }
Build Process:
- Update the
__version_info__
inside of the application. Commit and push. - Tag the release with the version.
git tag <version> -m "Release"; git push --tags
- Build the release
rm -rf dist build *egg-info; python setup.py sdist bdist_wheel
- Upload the data
twine upload dist/*
Have fun!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_agilesites-1.0.2rc2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 013cfd4fca566b5e29886691fea6e9ad072542c045eed1e36a68e0d2d9ee7152 |
|
MD5 | e2e6e2365df929d2ac77c490790da79d |
|
BLAKE2b-256 | dd7661821d5e5819ee59b8a00a28d14aeea9358429aeb5065c9b3c8a522bcf5d |
Hashes for django_agilesites-1.0.2rc2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31f9695a854c42826d221a9928b695a1db5decbf988f75bb285ed7e115b1faba |
|
MD5 | 9388ec6cf6cf6a76898ee46107687382 |
|
BLAKE2b-256 | 49432a7c2060a31b6f5d0e843e78e7a6538e07ae10d9b8bac6f19d9182bf325e |