The monolith monster
The “application” is the whole site — no
apps, no components, no modules.
Makes heavy use of site-wide logic:
middleware, context processors and
custom plugin-like concepts.
The Django mindset:
A great and powerful respect for data.
Model the data correctly and the rest
of the site will just fall out of that.
Denormalization is all well and good, but
never throw data away.
class BaseObject(models.Model):
creation_date = models.DateField()
…
class Animal(BaseObject):
…
class Vegetable(BaseObject):
…
class Mineral(BaseObject):
…
Without a concrete base class:
>>> Animal.objects.all()
SELECT ... FROM animal;
With a concrete base class:
>>> Animal.objects.all()
SELECT ... FROM "animal" INNER JOIN "baseobject"
ON ("animal"."baseobject_ptr_id" = "baseobject"."id")
What you want:
>>> BaseObject.objects.all()
[<Animal: Frog>, <Vegetable: Carrot>, <Mineral: Gold>, ...]
What you get:
>>> BaseObject.objects.all()
[<BaseObject: 1>, <BaseObject: 2>, <BaseObject: 3>, ...]
So maybe you try something like:
def get_some_of_everything():
qs = BaseObject.objects.all()
for obj in qs:
for cls in BaseObject.__subclasses__():
try:
obj = cls.objects.get(baseobject_ptr=obj)
break
except cls.DoesNotExist:
continue
yield obj
“Our site worked fine in development
and testing, and was working
wonderfully for the first few months.
“But we just added a bunch more data,
and now our homepage takes 27
seconds to load.”
If you must get fancy:
Abstract base classes don’t suffer from
these performance problems.
Denormalize into a UI-ordered
auxiliary model.
Non-relational databases work
particular well here (I like SOLR).
Those who do not
understand PYTHONPATH
are doomed to failure.
>>> import sys
>>> sys.path
['',
'/Library/Python/2.6/site-‐packages/pip-‐0.8-‐py2.6.egg',
'/Library/Python/2.6/site-‐packages/pdbpp-‐0.7-‐py2.6.egg',
'/Library/Python/2.6/site-‐packages/Pygments-‐1.4-‐py2.6.egg',
'/Library/Python/2.6/site-‐packages/wmctrl-‐0.1-‐py2.6.egg',
'/Library/Python/2.6/site-‐packages/pyrepl-‐0.8.2-‐py2.6.egg',
...
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
...
'/Users/jacob/.local/lib/python2.6/site-‐packages',
'/Library/Python/2.6/site-‐packages',
...]
>>> import re
>>> re
<module 're' from '/System/Library/Frameworks/Python.framework/Versions/
2.6/lib/python2.6/re.pyc'>
$ ./manage.py shell
>>> import dashboard.models
>>> dashboard.models
<module 'dashboard.models'
from '/Users/jacob/Projects/djdash/dashboard/models.pyc'>
>>> import djdash.dashboard.models
>>> djdash.dashboard.models
<module 'djdash.dashboard.models'
from '/Users/jacob/Projects/djdash/../djdash/dashboard/models.pyc'>
>>> djdash.dashboard.models.Metric is dashboard.models.Metric
False
You might have an
import issue if…
“Hey, many-to-many relations don’t
show up in the admin.”
“What’s up with these import errors
when I deploy under mod_wsgi?”
“Grrr… assertRaises doesn’t work!”
Fixing import madness
1. Use non-project-relative imports
(import app.models, not import
project.app.models).
2. Use relative imports (from . import x)
where possible (see http://bit.ly/pep328).
3. Stop using manage.py.
Don’t do this …
INSTALLED_APPS += [p for p in os.listdir(BASE)
if os.path.isdir(p)]
… or this …
urlpatterns = patterns('', ...)
for app in settings.INSTALLED_APPS:
if not app.startswith('django'):
p = url('^%s/' % app, include('%s.urls') % app)
urlpatterns += patterns('', p)
… or this.
MIDDLEWARE_CLASSES = [...]
def callback(arg, dirname, fnames):
if 'middleware.py' in fnames:
m = '%s.middleware' % os.path.split(dirname)[-‐1])
MIDDLEWARE_CLASSES.append(m)
os.path.walk(BASE, callback, None)
Python’s design is predicated
on the proposition that
code is more often
read than written.
lead developer, django\nconsultant, revsys, where I help companies scale web apps.\n
lead developer, django\nconsultant, revsys, where I help companies scale web apps.\n
This is how many lines of Django code I&#x2019;ve read over the last 2 years or so.\n\nBy comparison: Django: 120kloc, Python stdlib: 300kloc, pypy 550kloc (or 1m incl stdlib)\n\nMuch of this code has been good; some of it has been great; some very very bad. My goal today is to share with you some of what I&#x2019;ve learned - to suggest certain successful patterns, and warn you away from other noxious ones.\n
The theme that&#x2019;s emerged here: y&#x2019;all are far to damned clever.\n\n\n
One of Simon&#x2019;s favorite quips. Also known as &#x201C;KISS&#x201D; and a bunch of other things, but what I like about this particular formulation is the word &#x201C;possibly&#x201D;. It&#x2019;s not &#x201C;do the simple thing that you know will work&#x201D;; it&#x2019;s &#x201C;do something that *could* work&#x201D;. If it doesn&#x2019;t, *then* you can get more complex.\n\nDjango does not lend itself very well to overengineering. Keep it small, keep it simple, keep it clean.\n
Pattern 1: small is beautiful.\n
This is easiest to explain by starting with the anti-pattern, so let&#x2019;s start there. I see, from time to time, Django apps that are just one huge ball of wax - a monolith. Instead of multiple apps, there&#x2019;s just a single app with all the code in it.\n\nTypically these don&#x2019;t grow well at all. Because there&#x2019;s no real thought to factoring, the web gets more and more tangled, and you end up needing to fall back on site-wide things like middleware and context processors to get bits into the right place. At the extreme, people end up inventing their own plugin-like concepts. Remember: Django&#x2019;s *got that* -- INSTALLED_APPS -- so if you&#x2019;re reinventing that system you&#x2019;re cutting against the grain.\n
\n
I&#x2019;ll give one example. Client wanted us to review his code, he told us that it was 20kloc. Sounds fairly small and easy to review, until &#x2026;\n
Wait, where&#x2019;s the rest of the site?\n
Groan.\n
I often like to graph the models to get a handle on how the data fits together. The red box is just this one app; something on the order of 200 or so models in there.\n\nThere was stuff in there like &#x201C;Customer&#x201D; and &#x201C;Customer2&#x201D; &#x2014; with such a big ball of wax, people were afraid to make changes, not knowing what the ramifications would be.\n
Large modules are generally considered &#x201C;code smell.&#x201D; All-in-one design prevents reuse. You&#x2019;ll need to introduce random, unrelated code. Monoliths are hellish to test.\n\nMany great Django apps are very small. Even a lot of &#x201C;simple&#x201D; Django sites commonly have a dozen or more applications in INSTALLED_APPS. If you&#x2019;ve got a complex site and a short application list, something&#x2019;s probably wrong.\n
\n
Here&#x2019;s what (the data parts of) a well-designed site look like. This is a selection of 5 apps from a larger project, but note how easily I can pull them out -- there&#x2019;s not any tendrils out of here[*]\n\nI want to particularly point out the faqcreator app. The system here is a ticketing and knowledge base system, and one requirement was the ability to quickly convert a ticket to an FAQ entry. I could put this logic in the FAQ system., but then it would create a circular dependency between tickets and faqs, which makes no sense and prevents reuse. So I introduced a faqcreator that depends on both.\n\nRemember: dependencies are just fine, but they should be logical, and they should be linear.\n\n[*] actually there&#x2019;s an FK to user but I typically omit that -- I consider Django apps fair game for deps.\n
\n
\n
\n
These make up the bulk of what you&#x2019;ll write as a Django dev, usually.\n
\n
\n
\n
\n
\n
\n
Pattern two: model your damned data. aka Django is not a CMS.\n
A typical &#x201C;CMS&#x201D;. This makes me sad sad sad.\n
ca 2003 Adrian/Simon working at the LJW; content managed in a (reasonably good, custom built) CMS. But you just can&#x2019;t pull information out of CMSes\n\nexample: gas prices. every morning, a reporter would call a few gas staions in lawrence and ask about gas prices. Then he&#x2019;d open the cms and type &#x201C;Shell: $1.82. Quick Stop: $1.88&#x201D;, etc. This is terrible: no way to get historical data, no way to graph changes over time, no way to build a &#x201C;closest gas to me&#x201D;, etc. This is turning &#x201C;data&#x201D; into &#x201C;text&#x201D;, and readers predictably found these &#x201C;stories&#x201D; useless. Eventually the reporter had to stop. Imagine if instead we&#x2019;d collected that data as data...\n\nDjango started as a reaction against CMSes. This isn&#x2019;t to say that CMSes are bad. But if you want one, Django isn&#x2019;t it.\n
Instead, Django really really wants you to model your data. There&#x2019;s no such thing as content: there&#x2019;s gas stations and price measurements; public officials and speaking appearances; photographs and infographics.\n\nAnother example: look at lanyrd. Plenty of people have made conference web sites, but Simon followed (because helped invent!) the Django philosophy, and the site&#x2019;s incredibly useful because if its powerful respect for the data.\n
One particularly pernicious form the &#x201C;content&#x201D; issue takes is what I all the &#x201C;everything-is-a&#x201D; antipattern.\n
Starts here.\n
So you do something like this.\n\nRemember, though: databases are *not* OO, so what this actually does is to create a foreign key from (Animal, Vegetable, Mineral) back to BaseObject.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
So consider what happens when you do queries.\n\nNow there&#x2019;s a &#x201C;hidden join&#x201D;. Now, the &#x201C;JOINs are evil&#x201D; thing is a bit of a myth, at least if you&#x2019;re using a grown-up database, but it&#x2019;s clear that the first query is a lot cheaper than the second.ways\n\nThis gets even worse if you&#x2019;ve got multiple levels of interitance.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
But here&#x2019;s where it gets really bad -- people *want* base classes to automatically &#x201C;narrow&#x201D; themselves to the appropriate subclass, but this isn&#x2019;t something Django&#x2019;s ORM can do. Indeed, ORMs that *can* do this (Hibernate, SQLA probably) can&#x2019;t do it efficiently.\n
So maybe you try something like this to scope things down. Now you&#x2019;re doing O(N) queries.\n
\n
One of the simplest performance metrics is the number of RTs between your web servers and the db server. As a rule of thumb, you can kinda assume that all queries take roughly the same time; it&#x2019;s the network round-trip that kills you. Remember: these queries are done synchronously, so even if the db can do a query in only 1ms this page would still take 1.8seconds to render!\n
At this point I hear you saying &#x201C;but this *is* a legitimate business need!&#x201D;\n\nSo give everything a creation date. Do 3 queries (Animal, Veg, Min) and then combine the lists.\n
At this point I hear you saying &#x201C;but this *is* a legitimate business need!&#x201D;\n\nSo give everything a creation date. Do 3 queries (Animal, Veg, Min) and then combine the lists.\n
One of Simon&#x2019;s favorite quips. Also known as &#x201C;KISS&#x201D; and a bunch of other things, but what I like about this particular formulation is the word &#x201C;possibly&#x201D;. It&#x2019;s not &#x201C;do the simple thing that you know will work&#x201D;; it&#x2019;s &#x201C;do something that *could* work&#x201D;. If it doesn&#x2019;t, *then* you can get more complex.\n\nDjango does not lend itself very well to overengineering. Keep it small, keep it simple, keep it clean.\n
If you need to get fancy -- you&#x2019;ve got 60 kinds of content you need to interleave -- then it&#x2019;s time to denormalize.\n
Pattern/anti-pattern 3: not understanding PYTHONPATH.\n\nI see a *huge* amount of confusion about imports and the python path.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Brief explanation of what pythonpath is and how imports work, kinda.\n
Consider, a basic project - very simple, just one app.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
sadly, manage.py lets you access your models under two separate paths, and this causes no end of confusion.\n
How you know you&#x2019;re getting bitten by this.\n
The problem: manage.py is broken. It adds &#x201C;.&#x201D; and &#x201C;..&#x201D; to PYTHONPATH. It does this to make the tutorial easier, and to prevent having to explain PYTHONPATH to new django users, but this was a mistake.\n
Always use app-imports: this makes it easy to spin apps out of the project if you need to.\n\nTry to use relative imports if you&#x2019;re on 2.5 or higher -- really really makes this easier.\n\nDelete manage.py.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
Wait, if I delete manage.py how do I interact with my app?\n\nUse django-admin.py.\n\nThis doesn&#x2019;t do the pythonpath malarky -- you have to be explicit!\n\nThis --settings thing is important for a semi-related reason; make a note for later.\n
You can automate most of this with virtualenv, and it&#x2019;s kinda great.\n
Lastly, I&#x2019;ll talk a bit about settings. I see people doing the craziest stuff with settings...\n\n(and urls - urls are a special form of setting)\n
Not too bad... but it *does* defeat the whole purpose of INSTALLED_APPS. The point is to be explicit about what&#x2019;s loaded. Django&#x2019;s trying to make sure you&#x2019;re only using what&#x2019;s needed. If you circumvent this, things start randomly breaking when you make directories.\n\nI even saw this become a security hole: they allowed uploads into a media/ directory, and I uploaded a &#x201C;models.py&#x201D;. Oops.\n
Then it gets more crazy. People do stuff like this to dynamically load urls because apparently adding a line to urls.py is too much work...\n
... and even scary stuff like there.\n\nThere&#x2019;s actually a couple of bugs here; they&#x2019;re left as exercises to the reader.\n
\n
There&#x2019;s no good reason not to just make settings simple data structures.\n
There&#x2019;s no good reason not to just make settings simple data structures.\n
The problem: differences between development (mac laptop), testing (ci), staging, production.\n\nI see lots of unneeded complexity here, too. What&#x2019;s the most Django-esque, least magical solution?\n
This is a very common pattern, and it needs to die.\n
Here&#x2019;s how you explain the pattern. Anyone see what&#x2019;s wrong?\n
There are other reasons why this pattern sucks -- e.g. since you&#x2019;re importing overrides into the &#x201C;base&#x201D;, you can&#x2019;t do stuff like &#x201C;INSTALLED_APPS.append()&#x201D;. But EVERYTHING GOES IN SOURCE CONTROL!\n
\n
\n
\n
\n
\n
One of Simon&#x2019;s favorite quips. Also known as &#x201C;KISS&#x201D; and a bunch of other things, but what I like about this particular formulation is the word &#x201C;possibly&#x201D;. It&#x2019;s not &#x201C;do the simple thing that you know will work&#x201D;; it&#x2019;s &#x201C;do something that *could* work&#x201D;. If it doesn&#x2019;t, *then* you can get more complex.\n\nDjango does not lend itself very well to overengineering. Keep it small, keep it simple, keep it clean.\n