Emma
Diverse decks of slide mainly about Django
By Emmanuelle Delescolle
ALLOWED_HOSTS = ['*']
Unsecure
Doesn't handle domain aliases
Manually adding each domain to ALLOWED_HOSTS
Requires an application restart
Error-prone
## settings.py
from airavata.utils import AllowedSites
ALLOWED_HOSTS = AllowedSites()
When
DEBUG = False
urls.py is only evaluated once!
Sites modules
##urls.py
from airavata import urls
urlpatterns = urls.UrlPatterns([
# Place your patterns here
...
url(...),
])
##sites/mydomain_com/urls.py
urlpatterns += [
url(
r'^' + settings.STATIC_URL[1:] + r'(?P<path>.*)$',
serve,
{'document_root': settings.STATIC_ROOT}
),
]
##settings.py
TEMPLATES = [
{
...
## Make sure APP_DIRS is set to False
'APP_DIRS': False,
'OPTIONS': {
...
## add a loaders option
'loaders': (
'airavata.template_loader.Loader',
# 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader'
),
},
},
]
##settings.py
STATICFILES_FINDERS = (
"airavata.staticfiles_finder.SiteFinder",
# "django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
from django.views.generic import DetailView, ListView
from airavata.views import SiteFilteredViewMixin
from .models import MyModel
class MyModelListView(SiteFilteredViewMixin, ListView):
model = MyModel
class MyModelDetailView(SiteFilteredViewMixin, DetailView):
model = MyModel
site_field = 'base_site'
Project on BitBucket: https://bitbucket.org/levit_scs/airavata/overview
Read The Docs: http://django-polla.readthedocs.org/en/latest/index.html
By Emma
PyConUK 2015 talk