Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Postgres user gone after lion update
-
Cài đặt Django trên Dreamhost
Mình đang sử dụng dịch vụ hosting trên Dreamhost và thấy khá thú vị vì các tính năng mà nó support từ SVN, Unlimited Bandwidth và Unlimited Storage. Thú vị hơn là mình có thể cài Django trên đó để có thể thực hành được các ứng dụng nhỏ. Bài viết này sẽ cụ thể hóa cách cài đặt Django trên Dreamhost.Mặc định trên Dreamhost đã có cài Django, chúng ta có thể thấy được điều này nếu vào console python và gõ lệnh>> import django >> django.get_version()Kết quả trả về sẽ là version hiện tại của Django được cài trên host. Và mình có được version là 1.2.Hiện tại version mới nhất của Django là 1.3. Để cài đặt được version mới nhất ta làm theo các bước sau.Cài đặt Python virtualenv để có thể tự mình cài đặt các Python package. Kiểm tra trang virtualenv pypi để lấy bản mới nhất.wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.3.tar.gz tar xzf virtualenv-1.6.3.tar.gz python virtualenv-1.6.3/virtualenv.py $HOME/local rm -rf virtualenv* export PATH=$HOME/local/bin:$PATHBạn nên sửa lại ~/.bashrc như sauexport PATH=$HOME/local/bin:$PATHKiểm tra lại đường dẫn đến python bằng lệnh which python, kết quả trả về là /home/youruser/local/bin/python chứ không phải là /usr/bin/python.Giờ chúng ta có thể cài (cập nhật) … -
Opportunism and other approaches to action in Software Architecture
Venkatesh Rao's onthology of decision making can be a source of inspiration for software architectures. I discuss four approaches to action taking in web development. -
A taste of the Django on inside Mozilla, Sheriffs Duty
One of the many great things about working for Mozilla is that everything we do is Open Source. Even our wiki is open (however we have an internal wiki for corporation boring stuff such as meeting rooms, HR etc.) Last week I wrote an internal application for Mozilla's build engineers. Essentially it's a roster that lists one user per day and it's helped by being visualized as a calendar and as a vCal export. It's very unlikely that anybody outside Mozilla will find this particularly useful. But who knows, perhaps other companies have needs to take turns to sheriff build machines. Anyway, the project was easy to write because we have something called Playdoh. It's a set of nifty and useful settings and a folder structure and it comes with a submodule called "playdoh-lib" which is stuffed with lots of useful packages that you'll most likely want to use. If you browse Playdoh on Github it might look like a lot of stuff but after a second look you'll see that there's actually almost no code. So don't you dare to play the "bloat card"! :) What this app uses is TastyPie for the REST API which was awesome by … -
A taste of the Django on inside Mozilla, Sheriffs Duty
One of the many great things about working for Mozilla is that everything we do is Open Source. Even our wiki is open (however we have an internal wiki for corporation boring stuff such as meeting rooms, HR etc.) Last week I wrote an internal application for Mozilla's build engineers. Essentially it's a roster that lists one user per day and it's helped by being visualized as a calendar and as a vCal export. It's very unlikely that anybody outside Mozilla will find this particularly useful. But who knows, perhaps other companies have needs to take turns to sheriff build machines. Anyway, the project was easy to write because we have something called Playdoh. It's a set of nifty and useful settings and a folder structure and it comes with a submodule called "playdoh-lib" which is stuffed with lots of useful packages that you'll most likely want to use. If you browse Playdoh on Github it might look like a lot of stuff but after a second look you'll see that there's actually almost no code. So don't you dare to play the "bloat card"! :) What this app uses is TastyPie for the REST API which was awesome by … -
Translated text images for lazy programmers
In a previous post about django translations in this blog, I shared how to achieve a quick system that allowed me to manage translations stored in models and served using a template tag. In this post I will explain how to serve images that contain translated text and, hence, a localized image exists for each language. In my case, images are referenced from <img> HTML tags in templates and from CSS files. First of all we must create a basic structure in our img/ and css/ media folders, creating inside a directory for each language code we will use. For example, if we have two languages -- english and spanish -- we would create img/en/, img/es/, css/en/ and css/es/. In the CSS folders, the same files must be initially copied. If we have, for instance, just one style.css file, it must be both in css/en/style.css and css/es/style.css: css/ en/ style.css es/ style.css For the images, we should create the images that will be translated into each language code folder. All CSS files will reference the non-translated images in the same way, but their own file path to the translated image. I'll give an example. Let's say we have one background … -
A common Django/Postgres unicode fail
If you just installed postgres and created a database, Django will probably fail to bring you unicode happiness. The chances are that your site suffers from this error, even if you have not seen it yet. How to spot and fix "DatabaseError: value too long for type character varying"? Read the blog post! -
Where Django programming and Google Analytics meet
We just recently discovered an issue where a programming decision affected the ease (or lack thereof) of establishing goal funnels in Google Analytics. What we also discovered was that it was completely avoidable with a little better communicatioin between our Django programming staff and our analytics staff. As is typical ... -
Sử dụng Amazon SES với Django
Amazon Simple Email Service (Amazon SES) là một giải pháp email dễ dùng và hiệu quả cho các ứng dụng. Tuy Amazon SES đang được phát triển ở giai đoạn beta nhưng nó đã đáp ứng tương đối đầy đủ nhu cầu nhận và gửi mail.Để đăng ký sử dụng Amazon SES chúng ta làm theo các bước hướng dẫn này để xác minh địa chỉ email cần sử dụng. Nếu làm việc trên môi trường Windows chúng ta cần đọc thêm hướng dẫn này nữa. Trên môi trường Ubuntu khi thực hiện quá trình verify email có thể sẽ gặp thông báo lỗi như là "Can't locate XML/LibXML.pm in @INC....". Lỗi này xảy ra khi máy của bạn chưa có thư việc XML của Perl. Để khắc phục bạn cài thêm 2 thư viện của Perl bằng dòng lệnhsudo apt-get install libio-socket-ssl-perlsudo apt-get install libxml-libxml-perlSau khi verify email thành công chúng ta có thể thực hiện gửi mail, nhưng chỉ gửi và nhận với địa chỉ email mà đã được đăng ký, chủ yếu dùng để debug trước khi thực hiện tiếp quá trình đăng ký Production để gửi email đến các địa chỉ khác.Công việc tiếp theo là … -
Filtering querysets in django.contrib.admin forms
I make extensive use of the django admin interface. It is the primary tool for our support team to look at user data for our product, and I have stretched it in many ways to suit my needs. One problem I often come back to is a need to filter querysets in forms and formsets. Specifically, the objects that should be presented to the admin user in a relationship to the currently viewed object should be filtered. In most cases, this is something as simple as making sure the Person and the Units they work at are within the same company. There is a simple bit of boilerplate that can do this. You need to create a custom form, and attach this to the ModelAdmin for the parent object: {% highlight python linenos %} from django.contrib import admin from django import forms from models import Person, Unit class PersonAdminForm(forms.ModelForm): class Meta: model = Person def __init__(self, *args, **kwargs): super(PersonAdminForm, self).__init__(*args, **kwargs) # This is the bit that matters: self.fields['units'].queryset = self.instance.company.units class PersonAdmin(admin.ModelAdmin): form = PersonAdminForm {% endhighlight %} In actuality, it is a little more complicated than this: you need to test if the selected object has a company, … -
Django: Using Caching to Track Online Users
Recently I wanted a simple solution to track whether a user is online on a given Django site. The definition of "online" on a site is kind of ambiguous, so I'll define that a user is considered to be online if they have made any request to the site in the last five minutes. I found that one approach is to use Django's caching framework to track when a user last accessed the site. For example, upon each request, I can have a middleware set the current time as a cache value associated with a given user. This allows us to store some basic information about logged-in user's online state without having to hit the database on each request and easily retrieve it by accessing the cache.My approach below. Comments welcome.In settings.py:# add the middleware that you are about to create to settingsMIDDLEWARE_CLASSES = ( .... 'middleware.activeuser_middleware.ActiveUserMiddleware', ....)# Setup caching per Django docs. In actuality, you'd probably use memcached instead of local memory.CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'default-cache' }}# Number of seconds of inactivity before a user is marked offlineUSER_ONLINE_TIMEOUT = 300# Number of seconds that we will keep track of inactive users for before # their last … -
Python and OS X Lion
-
Convention Over Configuration: Django Settings
I've been working with Django for over five years. Even though **I don't consider myself as a programmer**, one of the advantages I seem to have over less experienced Django developers is that I've developed (together with <a href="http://www.syneus.fi/" title="Syneus Solutions -- In Finnish">our team</a>) strong conventions on how I work. This makes developing faster and generally more enjoyable. Conventions are a tool for efficient workflow and to help read and understand code by other people better. Like so many tools, conventions too can be taken to extremes to the point when then they become magic (Rails, anyone), which in Python community is <a href="http://www.reddit.com/r/Python/comments/ex54j/seeking_clarification_on_pylonsturbogearspyramid/c1bo1v5">considered a bad practice</a>. The Python community has a name for code that feels right: that kind of code is _pythonic_. Good, pythonic conventions are logical and easy to remember but also explicit. In other words good conventions should make sense when you see them first time. Django has many documented conventions (like that models should live in `models.py` and views in `views.py`) and even <a href="https://docs.djangoproject.com/en/1.3/internals/contributing/#coding-style">coding guidelines</a> but there are many places that could use more stronger or better ones. This article is first in a series of discussing conventions related to Django. My goal … -
Convention Over Configuration: Django Settings
This is a first article in a series about DRY and pythonic conventions for Web development with Django. The goal is to share and discuss common problems in everyday Django development where there is no documentation nor an obvious way of do it. -
How to always exclude specific Django applications from unit testing
Sometimes your Django project will include applications whose unit tests will never pass. In this post, I will explain a quick fix for this, and, probably more usefully, try to explain how and why I developed the code. -
How to always exclude specific Django applications from unit testing
Sometimes your Django project will include applications whose unit tests will never pass. In this post, I will explain a quick fix for this, and, probably more usefully, try to explain how and why I developed the code. -
Disabling South Migrations
It is often handy to disable (either temporarily or permanently) South migrations for an app. “Disable” in this context means preventing an app’s migrations from being executed so that the app is managed via syncdb while in this state. A couple scenarios where this could be useful… -
An alternative RapidSMS router implementation (with Celery!)
We've been using RapidSMS, a Django-powered SMS framework, more and more frequently here at Caktus. It's evolved a lot over the past year-- from being reworked to feel more like a Django app, to merging the rapidsms-core-dev and rapidsms-contrib-apps-dev repositories into a single codebase (no more submodules!), to finally becoming installable via pypi. The "new core" ... -
An alternative RapidSMS router implementation (with Celery!)
We've been using RapidSMS, a Django-powered SMS framework, more and more frequently here at Caktus. It's evolved a lot over the past year-- from being reworked to feel more like a Django app, to merging the rapidsms-core-dev and rapidsms-contrib-apps-dev repositories into a single codebase (no more submodules!), to finally becoming installable via pypi. The "new core" is in a great state now and is much easier to work with. However, one particular aspect of RapidSMS, the route process, has always been complicated and confusing to deal with. Tobias began the conversation on this issue after returning from a 6-week long UNICEF project in Zambia. He summarized the route process like so: -
Python and Django class/hackathon!
The Los Angeles Python community (LA Django and LA PyLadies) is meeting in Santa Monica on July 23rd to teach Django and hack on all things Python on Saturday, July 23rd. The day will start with a Django class based on the official Django tutorial, then turn into a general hackathon, and finish up with lighting talks.Leading the event is noted Pythonista Katharine Jarmul. As Katharine is giving the talk on web scraping at DjangoCon US, I'm hoping we can get her to give a lightning talk on the subject.Learning DjangoSandy Strong will lead the effort to teach people the fundamentals of Django. Besides all things Django and devops, Sandy is presenting the testing talk at DjangoCon US. And if that isn't good enough for you, she won't be alone teaching - there will be a bunch of us developers experienced with Django there to to provide her with support.Even if you already know Django, please come and hang out for the first half! You can either help out others or work on your own project.Hacking Python and DjangoThe second half of the day will be about working on whatever you want. If you are new to Django and want to finish … -
Creantbits un 15 de juliol
Ahir divendres 15 hi hagué una nova edició del creantbits. Aquesta vegada enlloc de que la inscripció es fes en un comentari al blog, ho ferem amb una aplicació creada ad-hoc i que serví per experimentar amb un hosting de Python. El hosting va caure un pic en el procés d'inscripció (després de tot encara està en beta), però la gent d'Eldarion va respondre i en poques hores estava una altra vegada operatiu. L'aplicació en si crec que ha respost bastant bé, tot i estar feta en quatre potades. Ha permés a la gent que s'havia inscrit prest i després no ha pogut venir, fer-ho saber ràpidament i comunicar-ho al següent de la llista d'espera. Tot d'una que tengui una estona més miraré de documentar l'aplicació (que el codi ja hi està) i posar-ho a bitbucket per tal que si hi ha més gent que s'animi entre tots poguem fer un bon programa de gestió d'events. De l'event en sí poca cosa a dir, la sala plena d'amics, gent que ja coneixia personalment i gent que he pogut desvirtualitzar per primera vegada. Però la part important és amics, això fa que parlar en públic sigui molt menys estressant i també … -
Debian init script for virtualenv'd gunicorn_django
I recently moved my projects to gunicorn and needed init scripts. Here's what I'm currently using. I have the gunicorns running behind nginx, so you might want to tweak the IP and PORT settings. It might also be nice to use start-stop-daemon. #! /bin/sh ### BEGIN INIT INFO # Provides: gunicorn-initscript # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Should-Start: $nginx # Default-Start: 30 2 3 4 5 # Default-Stop: 70 0 1 6 # Short-Description: virtualenv + gunicorn + nginx debian init script # Description: virtualenv + gunicorn + nginx debian init script ### END INIT INFO # Author: Nicolas Kuttler <hidden> # # Please remove the "Author" lines above and replace them # with your own name if you copy and modify this script. # # Enable with update-rc.d gunicorn-example start 30 2 3 4 5 . stop 70 0 1 6 . # (parameters might not be necessary, test) # Do NOT "set -e" PROJECT=/path/to/project/ VIRTUALENV=/path/to/virtualenv PORT=8888 LOGDIR=/var/log/gunicorn/ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/bin:/usr/bin USER=www-data GROUP=www-data IP=127.0.0.1 WORKERS=5 # I am lazy and just call the init script gunicorn-project NAME=`basename $0` DESC=$NAME LOGFILE="$LOGDIR$NAME.log" PIDFILE="$PROJECT$NAME.pid" CMD="gunicorn_django --user=$USER --group=$GROUP --daemon … -
Debian init script for virtualenv'd gunicorn_django
I recently moved my projects to gunicorn and needed init scripts. Here's what I'm currently using. I have the gunicorns running behind nginx, so you might want to tweak the IP and PORT settings. It might also be nice to use start-stop-daemon. #! /bin/sh ### BEGIN INIT INFO # Provides: gunicorn-initscript # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Should-Start: $nginx # Default-Start: 30 2 3 4 5 # Default-Stop: 70 0 1 6 # Short-Description: virtualenv + gunicorn + nginx debian init script # Description: virtualenv + gunicorn + nginx debian init script ### END INIT INFO # Author: Nicolas Kuttler <hidden> # # Please remove the "Author" lines above and replace them # with your own name if you copy and modify this script. # # Enable with update-rc.d gunicorn-example start 30 2 3 4 5 . stop 70 0 1 6 . # (parameters might not be necessary, test) # Do NOT "set -e" PROJECT=/path/to/project/ VIRTUALENV=/path/to/virtualenv PORT=8888 LOGDIR=/var/log/gunicorn/ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/bin:/usr/bin USER=www-data GROUP=www-data IP=127.0.0.1 WORKERS=5 # I am lazy and just call the init script gunicorn-project NAME=`basename $0` DESC=$NAME LOGFILE="$LOGDIR$NAME.log" PIDFILE="$PROJECT$NAME.pid" CMD="gunicorn_django --user=$USER --group=$GROUP --daemon … -
Debian init script for virtualenv'd gunicorn_django
I recently moved my projects to gunicorn and needed init scripts. Here's what I'm currently using. I have the gunicorns running behind nginx, so you might want to tweak the IP and PORT settings. It might also be nice to use start-stop-daemon. Raw #! /bin/sh ### BEGIN INIT INFO # Provides: gunicorn-initscript # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Should-Start: $nginx # Default-Start: 30 2 3 4 5 # Default-Stop: 70 0 1 6 # Short-Description: virtualenv + gunicorn + nginx debian init script # Description: virtualenv + gunicorn + nginx debian init script ### END INIT INFO # Author: Nicolas Kuttler <hidden> # # Please remove the "Author" lines above and replace them # with your own name if you copy and modify this script. # # Enable with update-rc.d gunicorn-example start 30 2 3 4 5 . stop 70 0 1 6 . # (parameters might not be necessary, test) # Do NOT "set -e" PROJECT=/path/to/project/ VIRTUALENV=/path/to/virtualenv PORT=8888 LOGDIR=/var/log/gunicorn/ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/bin:/usr/bin USER=www-data GROUP=www-data IP=127.0.0.1 WORKERS=5 # I am lazy and just call the init script gunicorn-project NAME=`basename $0` DESC=$NAME LOGFILE="$LOGDIR$NAME.log" PIDFILE="$PROJECT$NAME.pid" CMD="gunicorn_django --user=$USER --group=$GROUP … -
Debian init script for virtualenv'd gunicorn_django
I recently moved my projects to gunicorn and needed init scripts. Here's what I'm currently using. I have the gunicorns running behind nginx, so you might want to tweak the IP and PORT settings. It might also be nice to use start-stop-daemon. Raw #! /bin/sh ### BEGIN INIT INFO # Provides: gunicorn-initscript # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Should-Start: $nginx # Default-Start: 30 2 3 4 5 # Default-Stop: 70 0 1 6 # Short-Description: virtualenv + gunicorn + nginx debian init script # Description: virtualenv + gunicorn + nginx debian init script ### END INIT INFO # Author: Nicolas Kuttler <hidden> # # Please remove the "Author" lines above and replace them # with your own name if you copy and modify this script. # # Enable with update-rc.d gunicorn-example start 30 2 3 4 5 . stop 70 0 1 6 . # (parameters might not be necessary, test) # Do NOT "set -e" PROJECT=/path/to/project/ VIRTUALENV=/path/to/virtualenv PORT=8888 LOGDIR=/var/log/gunicorn/ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/bin:/usr/bin USER=www-data GROUP=www-data IP=127.0.0.1 WORKERS=5 # I am lazy and just call the init script gunicorn-project NAME=`basename $0` DESC=$NAME LOGFILE="$LOGDIR$NAME.log" PIDFILE="$PROJECT$NAME.pid" CMD="gunicorn_django --user=$USER --group=$GROUP …