
Django Best Practices — Updated for 1.4 - superchink
http://lincolnloop.com/django-best-practices/
======
bravura
I was excited for this guide, but unfortunately it was very short and light on
details.

I'm a novice Django programmer, and was surprised that I gained very little
knowledge by looking at this document. I wish I could report happier news.

I should be keeping a list of Django annoyances and questions, because then I
could propose a list of topics for Django best practices that I'd like to see
answered. But I can't remember them off the top of my head.

~~~
ipmb
If you think of anything, please file an issue
<https://github.com/lincolnloop/django-best-practices/issues>. It's written
for the novice-intermediate audience which can sometimes be hard to do when
you've been working in it daily for years.

------
est
I have few issues with this:

<https://github.com/lincolnloop/django-layout>

This structure leaves manage.py in the root path. Which mean other dirs will
pollute this area, like run/, deploy/, log/, config/, lib/, bin/, cronjobs/,
etc. You dirs woud stack to a long list.

I would suggest something like this:

    
    
        root/
          src/
            manage.py
          lib/
          run/
          docs/
          config/

~~~
ipmb
Yeah, a lot of this is personal preference and obviously, there's a million
ways to do it. Our perspective is that manage.py is a script (you never import
it as a Python module) so we bump it out and install to your path using
setup.py.

------
mik4el
Thanks! Good starting point. I'd like a section on using django on cloud
services, e.g. AWS Elastic beanstalk. Another best practise I'd want is
scheduling scripts with [https://docs.djangoproject.com/en/dev/howto/custom-
managemen...](https://docs.djangoproject.com/en/dev/howto/custom-management-
commands/) and Cron, or using Celery. There is much confusion on those topics
I think.

Edited some spelling...

~~~
Bockit
I'm not giving best practises as I'm myself fairly new to Django, this is just
a couple of packages to take a look at.

I've been deploying two projects to AWS very recently and we've been using
django-pipeline and django-storages (with s3 boto storage) for asset
management. ./manage.py collectstatic and all your static files are up on S3.
With a bit of finagling around[1] you can even have user uploads hit there
seamlessly as well.

[1]: [http://stackoverflow.com/questions/10390244/how-to-set-
up-a-...](http://stackoverflow.com/questions/10390244/how-to-set-up-a-django-
project-with-django-storages-and-amazon-s3-but-with-diff)

EDIT: Pipeline isn't necessary for storing static files on S3, but if you want
to compile SASS/LESS/cs files or any transforms really it works really well.

~~~
mik4el
Thank you!

------
senko
This recommends checking in your (instance-specific) settings to version
control. I know some people really push for the opposite
(<http://www.12factor.net/config>, canonical example is Heroku).

Myself, I'm swinging between the two still, haven't found a convincing
argument either way.

~~~
thezilch
We have canonical settings in our settings.py, while every environment imports
local settings from another conf. If it is necessary to have subsidiary
settings also source controlled, we could do that and have the environment
symlink its preference. Of course, additionally, the secondary settings could
have the same dance as the primary settings and allow for another level of
local configuration.

    
    
      # allow overriding of settings with $HOME/.sodahead
      rc = os.path.join(os.environ["HOME"], ".sodahead")
      if os.path.isfile(rc):
        with open(rc, "r") as fi:
          dotsodahead = imp.load_source("dotsodahead", rc, fi)
          settings = dict([(k, v) for k, v in vars(dotsodahead).items()
              if not k.startswith("__")])
          globals().update(settings)

------
TomaszZielinski
<shameless-plug> I've prepared something similar and posted it to HN some time
ago: <http://news.ycombinator.com/item?id=4488787>

Feel free to cross-pollinate! </shameless-plug>

------
pydanny
This is close to being a direct channel to my brain. Perfect!

