Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
We're Hiring!
Lincoln Loop is looking to hire a Python/Django developer. -
Using Proxy Models to Customize the Django Admin
Fellow Lincoln Looper, Martin Mahner, posted an excellent write up on how to use proxy models to separate staff and user accounts in Django’s admin. We frequently have a need for this in client projects, but people don’t often consider proxy models for this functionality. Here’s another scenario we came across recently where they came in useful. -
Installing GeoDjango Dependencies with Homebrew
Installing the GeoDjango dependencies (PostGIS, GEOS, Proj4, and GDAL) on OS X with Homebrew. -
Celery Tips
Following on yesterday's post about Virtualenv Tips, I will be talking about celery tips. Yesterday I talked about how to run celery with upstart easily, and today I'll be expanding on that below as well as talking about how to set it up using supervisord. Note: Also interesting, I wrote a Big list of django tips back in 2008, that still has a lot of good information. Running celery in development When you run celery in production, you should be using a queue on the backend. However, when you're running celery in development, it's nice to execute the code paths, but not actually need a queue. This is where the CELERY_ALWAYS_EAGER setting comes in handy. It makes celery run the code in process, but will make sure your code paths work correctly. I talk about this and more in my djangocon talk. Killing long running tasks On ReadTheDocs I would run into problems with celery tasks never returning. Luckily, celery has a way to handle this. The CELERYD_TASK_TIME_LIMIT setting lets you set the number of seconds that a task can run until it is killed. This is nice to make sure that a run-away task won't take down all your … -
Read the Docs Updates
Documentation writing will always be hard work. It's a much different mind-set than programming, and people that write good code might not necessarily write good docs. However, this is a known issue, and something that can't really be solved. What you can do is make it easier to write documentation. Every step along the way that you can give yourself an excuse to not write documentation is another undocumented open source project. Luke Plant has a great post up about how important documentation is, and I completely agree. I imagine a lot of the people using Django are using it because of the documentation. I think as members of the Django community, we need to build a culture of documentation within the greater Python world. Python does tend to have better documentation than a lot of languages, but it's still not nearly what it could be. Read the Docs exists to make it easier to host your Sphinx documentation. Over the weekend, Bobby, Jonas, and I added a bunch of new features to the site. I think it's getting to the point where there isn't an easier or better way to host the documentation for your Django project, and we're … -
Building a Django App Server with Chef: Part 4
Alternate title: There's no place like home! This is Part 4, the final part, of my Chef tutorial. Today we're talking about the odds and ends left over to make the server nice to use. You can check out the first 3 parts of the series: Part 1: Chef Beginnings Part 2: Python environment buildout Part 3: Deployment Today's code will be in the git repo under the tag blog-post-4. What we'll need So we have our app server up and running, and ready for traffic. Now we just need to add some other bits around the outside for it to be fully functioning and nice to use. Monitoring with Munin Background tasks with Celery A firewall for security A /etc/hosts file for talking with other nodes A .bash_profile file so that when you shell in you'll have a nice environment Let's get started. Monitoring with Munin For doing monitoring with munin, we're going to need to learn our final Chef concept, which is Templates. You should be pretty familiar with them already, except they use Erb, which is a template language that lets you embed Ruby. We're only going to be configuring the Munin node here. This assumes that … -
Virtualenv Tips
Virtualenv is a project that is indispensable for most Python devs these days. I am writing down some tips here so mainly for personal reference, and because I found them useful. Virtualenv & Upstart For my ReadTheDocs project, I was wanting to run celery as a background process that processes documentation building. I'm running Ubuntu, so their built-in upstart service seems like a logical choice. I really like upstart because of it's simple configuration, but it is rather undocumented (this Stanzas) page is a useful starting point). Carl Meyer pointed out to me that in order to get inside the context of a virtualenv, you don't need to munge your pythonpath or anything, but simply run the correct script from inside the virtualenv. So a simple /path/to/virtualenv/bin/django-admin.py celeryd was all that was needed to get inside the virtualenv's context. This also true of the python executable inside your python directory. /path/to/virtualenv/bin/python will allow you to run any python script inside of that virtualenv's context. I also wanted to be running my jobs as the user for that site, so sudo is the correct tool for that. The final file ended up looking like this: description "Celery for ReadTheDocs" start on … -
Building a Django App Server with Chef: Part 1
Alternate title: Fucking Chef, How does it work? When I started looking at Chef, I found it incredibly complex and lacking in fundamental documentation. This is going to be my experience understanding Chef while setting up a single server. This strategy can be used across multiple servers, with a little tweaking. I'd like to thank Jacob for the ideas and some of the inspiration behind the code and ideas. The code for this blog post can be found on github. It will be expanded as I write updates. Today's code will be using tag blog-post-1 in the repo. Goal I'm hoping to write a blog series that goes from explaining what Chef is, to having a working Django server, and to release all this code so that you can tweak and use it with your own servers. I'll be doing this to set up a new and configuration managed server for ReadTheDocs. There are a couple of other good chef intros available. However, they only get you to the super basic first step of setting up the server. Hopefully this series will be more in depth and useful to actually getting a real server running under Chef. Basic terminology Chef … -
Djangocon Talk
I just gave a talk title "Large problems, Mostly solved", which you will recognize if you've been reading this blog for a little while. I took my past series of Large problems posts, and expanded on them into a full talk. The video and slides are posted below. Thanks for the A/V team kicking ass this year and getting the videos posted in amazing time. Also many thanks to the conference organizers and volunteers who managed to make it all happen, it was a great time! Large problems, Mostly SolvedView more presentations from ericholscher. -
Building a Django App Server with Chef: Part 3
Alternate title: Show the world what you've got. This is Part 3 of my Chef tutorial. Today we're talking about deployment. You can check out the first 2 parts of the series: Part 1: Chef Beginnings Part 2: Python environment buildout Today's code will be in the git repo under the tag blog-post-3. What we'll need We'll be taking the Django application that we have on the server and actually deploying it. Let's make a list of what we'll need: A web server to sit in front and proxy requests A WSGI server A way to keep both of these things running A caching layer We'll be using Nginx, Memcached, Upstart, and Gunicorn. This is my preferred deployment stack as of late, mainly because of the simple setup. Let's get started A web server Getting Nginx up and running should be old hat by this point. We're going to need the package and service Resources, which will tell Chef to install and run it. cookbooks/main/recipes/nginx.rb package "nginx" do :upgrade end service "nginx" do enabled true running true supports :status => true, :restart => true, :reload => true action [:start, :enable] end cookbook_file "/etc/nginx/sites-enabled/readthedocs" do source "nginx/readthedocs" mode 0640 owner "root" … -
Building a Django App Server with Chef: Part 2
Alternate title: Actually doing something useful. Yesterday we covered the basics to getting started with Chef. You should have a remote server configured with chef, and have curl installed! Now lets go ahead and get some useful bits for your Django application. What we'll need So this is going to be based around the way that I set up my servers, so if this is different than you, I'm sorry. However, I think it is a pretty solid way of managing them. A lot of the ideas here are stolen from Travis when he set up the server for Pypants. So lets assemble a list of things we're going to want in order to get a super basic Django configuration running: A user to run our code as and who's home directory we'll store the data. A basic global python ecosystem, including setuptools and pip A virtualenv to store all the project-specific packages and code in A copy of the project that we'll be running Let's get started. The finished code for today is located on github, with the tag blog-post-2. It is a copy of the completed steps, so feel free to peek through that and come back here … -
Handling Django Settings Files
I have seen a lot of talk over the past couple years about how to handle different settings files and databases, synced between production and development. I have happened onto a way of doing it that makes me happy, and figured I would share it with the world. File structure I use a file structure that looks like this: project/ settings/ __init__.py (empty) base.py sqlite.py postgres.py The base.py contains all of the configuration options that are shared among the databases. INSTALLED_APPS, etc. All of the DATABASE settings should be specified in the more-specific files. As well as things that differ by environment, like remote servers, cache settings, cookie domains, and other things. This allows you to run the sqlite settings file, and have it be set to localhost, or whatever your development settings are. Then in production you just run against the postgres settings. A good example of this being used in practice is on Read the Docs. But wait, there's more! manage.py for dev ./manage.py is great for development. It is the easiest way to get started, and it automatically sets up your paths and stuff. With my setup, I actually explicitly set manage.py's settings file to the sqlite … -
Using Haystack to index non-database content
Over on ReadTheDocs, I wanted to build search around the documentation that we're hosting. I chose Haystack and Solr for this, because it's the best way to do search in Django these days. However, I've only ever used Haystack to index content that is in the database. I thought about trying to add all the rendered HTML from the documentation into the database, but that was a non-starter. I ended up adding a ImportedFile model to the database, which would contain the metadata for the HTML file: class ImportedFile(models.Model): project = models.ForeignKey(Project, related_name='imported_files') name = models.CharField(max_length=255) slug = models.SlugField() path = models.CharField(max_length=255) md5 = models.CharField(max_length=255) This allows me to link the SearchIndex in haystack to a model. Then the interesting part is in the Haystack SearchIndex, where I override the prepare_text method, allowing me to read the data in from the filesystem instead of from the database. class ImportedFileIndex(SearchIndex): text = CharField(document=True) author = CharField(model_attr='project__user') project = CharField(model_attr='project__name') title = CharField(model_attr='name') def prepare_text(self, obj): full_path = obj.project.full_html_path to_read = os.path.join(full_path, obj.path.lstrip('/')) try: content = codecs.open(to_read, encoding="utf-8", mode='r').read() return content except IOError: print "%s not found" % full_path site.register(ImportedFile, ImportedFileIndex) This means that I don't have to bloat my database with … -
EuroPython 2008, day 1
After a long year of exiting projects and neverending days at the office, I found myself again from EuroPython conference at Vilnius. The first conference day was full of interesting happenings, mainly reviving old and creating new connections. For all the sessions I attended during the day, I made some notes on few of them. Here are some basic notes about selected ones: Build an App in a Week by Marcin Kaszynski favpico.com etc Suprisingly many of the attendees (about half) use Django Use aDjango admin for users, too (not only for admins) ”Commit early, commit often” Share code only via vcs Use conventions @with_template decorator Note: you can use admin docs (template name) Tests Do save time self.login(), get, find coverage.py Instant Django This talk was interesting but didn’t really give much new stuff (at least for me). There was a discussion about how it makes sense to use convention of naming templates like app/viewname.html but I pointed out that if you for some reason want to part from that convention (that I believe most Django developers use), you can just point Django admin site help section to your designer and just document the fact in your modeldocs. No … -
Django Release Party in Helsinki
Heads up Finnish Djangonauts! Join us for celebrating the Django 1.0 release at Kaapelitehdas, Helsinki tomorrow evening (Saturday 6th) starting at 5 pm. More information on the location and attendees can be found on the event wiki page. This is an open invite — everyone is welcome! See you there! :) -
EuroPython 2008, day 3
For me, the main theme for the third and last day of the conference was Django. Day started with a session by Honza Král about Django newforms admin, which gave me a pretty good idea what I have to do in preparing for the migration to the new admin interface. Later on the day I had many interesting discussions about varions Django-related things, including ideas about having something like Django release party here in Europe, too. Turns out there are quite a lot Djangonauts here in EuroPython, we just arent organized very well so most of us don’t know about each other. Lively after-conference discussions about career choises, Web Design and working with Django in general were definitely the high point of the conference so far. A couple of hour later on the evening, decisions about quiet evening at the Sky Bar (at the 22nd floor of the conference hotel) were forgotten and, again, we headed for the old town. This time we ended up in some night club and, well, yeah, we had a great time :) -
EuroPython 2008, day 2
I skipped most of the sessions for the day as they didn’t seem even remotely interesting to me. But, the ones I did attend where really good. Last nights partying kept me pretty much in bed for better part of the morning. Descriptor tutorial by Raymond D. Hettinger was very good and I think it was actually the first conference tutorial ever that actually teached me something about programming and Python in general. There was quite a bit testing-related material on the Lightning talks. One thing I wrote down on my notes was the phrase ”Given enough tests, all bugs are shallow” (originally from Linus Torvalds in a form ”Given enough eyeballs, all bugs are shallow”). The keynote talk for the day was something that absolutely blew my mind. Hans Rosling talked about Gapminder and how statstical data and databases should be free. First thing that crossed my mind when listening to him was that ”I wonder if Adrian Holovaty has ever talked to this guy — they’d have much to talk about”. If you havent heard about Gapminder or Hans Rosling before, you should definitely see his talk on last years TED conference. In Django-terms, thats some cool shit … -
We Are Django
I’ve always thought that the community is one of the greatest things about Django. Not because Django isn’t great but because the people are just so awesome! Django People is a brilliant new site by Simon Willison and Natalie Downe which brings together Djangonauts all over the world. (Interestingly, I was talking about exactly this same idea yesterday with my friend, in the lines of “there should definitely be something like that”. Great minds think alike (I wish) :) I had the pleasure of meeting Simon and Natalie during the Europython conference last summer. Like every other Django people at the conference, they were super-nice and fun to share thoughts with. The various conversations we had with the Web-gang there were definitely one of the highlights of my last year. I hope that Django People will help in finding more same-minded people, both near you and when traveling around the world. If you are Djangonaut, add yourself to the site! And when you do, please include your picture and some information about yourself. It’s so much nicer to look at real faces than empty rectangles :) Here’s to many more Django friends. -
Django SXSW Lunch Meetup
Hey all you Djabgo devs roaming the halls of SXSW: let's do lunch... -
The basics of creating a tumblelog with Django
On my new homepage, a combined list of my tweets, bookmarks, and user comments on my site appear underneath my latest blog entries. I use a fun bit of Django code to pull these various items together, sorted by publication date, and I'd like to share how this bit of tumblelog-like functionality works. -
Introducing Django JumpToAdmin
Django JumpToAdmin displays links to admin change/delete/list pages when specified objects on a page are hovered over with the mouse. Once clicked, these links open the requested Django admin page in an iframe above the current page. Read on to see a screencast of the UI. -
Introducing CSS Prism, a CSS color inspector
After launching a new site at work in which colors from a previous site weren't replaced in the stylesheet, I decided to find a way to reveal all the colors used in any .css file. When I couldn't find a way, I made one. So today I'm launching CSS Prism, a CSS color spectrum inspector -
Design decisions and highlights of Scripps' newest local news site
Earlier this week, the team at Scripps Interactive Newspaper Group launched a major newspaper website overhaul for the Evansville Courier & Press in Evansville, IN. This project has been brewing for almost a year, and has been a full-time responsibility for some of us for more than six months. Here are some of my favorite changes for readers -
Finding a Django-friendly host just got a little easier
Djangofriendly celebrated its first birthday in March. In its first year, more than 16,000 visitors came by to find and share knowledge on hosting Django applications with various hosts. To celebrate Djangofriendly's birthday, I've gone into a bit of a code sprint, the first phase of which concluded this morning as the new code went live... -
Hosting Subversion on Webfaction
Recent projects at work have finally led me to incorporate Subversion into my Django development workflow. Once I saw the light, I wanted to manage my personal and client projects with the same efficiency, but hesitated to sign up for SVN hosting services on my own dime. Turns out I could add SVN hosting to my existing WebFaction account. Here's how.