Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Gunicorn zero-length bug fixed
Two weeks ago I wrote about a zero-length bug I encountered with gunicorn when running it under apache in certain cases and when using internet explorer. Corner case, but still. With some apache tweaking I managed to work around it (or solve it). I submitted a bug report suggesting a small doc update for this corner case and got a quick reply from the author asking me to try out the most recent release, as that apparently contained an fix for "chunked encoding". I hooked 0.12.2 up into my site instead of the 0.12.1 that I was using and yes, it fixes it! So hurray for open source and responsive authors! -
Django Models Mixins
One thing I've been experimenting with is model Mixins. For example, the aim is to create small abstract classes that are each focused around a particular function. These abstract classes can then be added to arbitrary models to apply those functions to models as desired.For example, say I define a RatingsFields abstract class and a TrackingFields abstract class. These abstract classes can be mixed into any other model that we wish to add rating or tracking functionality to. core/mixins.pyfrom djangoratings.fields import RatingField # 3rd party moduleclass RatingFields(models.Model): rating = RatingField(range=5) # 5 possible rating values, 1-5 class Meta: abstract = True class TrackingFields(models.Model): deleted_on = models.DateTimeField(blank=True, null=True) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Meta: abstract = True Since we applied the abstract classes to the Post model below, the model now has rating and tracking capabilities. This is useful to help simplify code where a lot of models share fields or methods with the same function.myapp/models.pyfrom core import mixins as core_mixinsclass Post(core_mixins.TrackingFields, core_mixins.RatingFields): name = models.CharField(max_length=128) slug = models.SlugField(max_length=128) ...Comments welcome.Joe -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por Valder
Guilherme, o download via git/svn por FTP é impossível. O que vc pode fazer é fazer isso em sua máquina e mandar por ftp para o servidor da UOL. O que dá para fazer e testar uma estrutura de diretórios diferentes da do tutorial. Algo como: public_html/Django public_html/meu_projeto public_html/.htaccess Ai no .htaccess vc manda o PYTHONPATH para o public_html/Django;public_html/meu_projeto Não fiz os testes, mas acho que é possível. Já que o apache não vai ligar para os exports, ele apenas enxerga as informações do .htaccess SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE meu_projeto.settings PythonInterpreter meu_projeto PythonOption django.root /meu_projeto PythonDebug On PythonPath "['/home/valdergall/public_html','/home/valdergall/public_html/Django'] + sys.path" Acho que se vc jogar o diretório que contém do diretório django que fica dentro do Django direto no public_html nem precisa ter 2 caminhos no python path. Mas eu não tenho certeza se vai funcionar. Outra opção é usar o virtualenv para o seu próprio ambiente de projeto e jogar todo o envproject no public_html. -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por Guilherme
E pra quem tem serivço de revenda e não tem acesso via ssh para fazer o download via trunk/git/svn o que fazemos? Já tentei o processo que o suporte recomendou copiar a pasta do projeto para uma pasta (public_html/meuprojeto) e colocar dentro dela o arquivo .htaccess isso está certo? não deu certo comigo. Tem outra solução? -
Audio recording in Django apps with flvar
flvar is a flash applet working with a media server and allows users to record audio clips on a website using it. To use it in a Django project you need to setup the media server like Red5, and map some hardcoded paths in flvar recorder to Django views and templates. -
Getting Django to work with uWSGI on Cherokee
* Installing uWSGI * Creating uwsgi.conf file /home/emilian/springmerchant dev.django_wsgi * -
CouchDB + Django + Couchdbkit
CouchDB + Django + Couchdbkit -
CouchDB + Django + Couchdbkit
Just some notes for future use. Couchdbkit: Searching by key: Document.view('document/all', key='') -
The state of python and the web - Armin Ronacher (PyGrunn conference)
Armin's a founding member of the pocoo team with projects like jinja2, werkzeug, sphinx and so. Python 3 is the elephant in the room that nobody's talking about. There's a lot of python 2 code and porting is turning out to be harder than expected. Some recent python developments: Unladen swallow is "resting". Development stopped. It was the number one hope to make python faster. Python 3.2 got released. Python's packaging is being worked on a lot. Pypy turns out to be quite fast nowadays. Really really fast. What's pypy? It is python written in python. Well, in "restricted python", which can be translated to C automatically. It is 3.7 till 40 times faster than regular cpython!!! Things that will work? Django, flask, pyglet, twisted, sqlite, ctypes and so on. A problem with pypy is that there's only experimental support for the python C API. And C-level extensions will always be slow. And there is no reference counting, so you need (for instance) to close files yourself. But, in summary, python 3 is where all the new language development is happening. What does python 3 mean? Unicode cleanup. All text-like things are either unicode text or a binary blob. The … -
The ten commands of security - Jobert Abma (PyGrunn conference)
He's an ethical hacker at online24, hacking SME and government websites as a job. Some items to keep in mind regarding security. Your application isn't the only attack vector. Your app is on a server. Who has access to that server? Which other apps run on that server? And the bigger the organization, the more chances for "social engineering": for instance mimicking an employee and asking for a password for xyz. Conduct risk assessments to identify risks. Identify the risks, only then can you take action on them. Rate your identified risks. Only trust your own code. And double check. It is not OK to rely implicitly on the underlying platform. Something that can solve a lot of major issues: security by design. Design it in. Centralize certain processes like validation or authentication and make them secure. Always be aware of technical issues. If you catch errors, make sure you know when something goes wrong because of catching the errors, for instance. Time (mis)management is a big problem. If you don't have enough time to properly do security, you'll have problems. Jobert thinks the big playstation hack was a security risk they were aware of, but just didn't have/got the … -
Redis in practice - Pieter Noordhuis (PyGrunn conference)
Pieter works on the core of Redis. The core is just two people, but still :-) So it was fun to have him give a talk here at this conference. Redis is "an advanced key/value store". You probably have heard of memcached. It is also a key/value store. Redis is something similar, but it has more data types. Memcached only stores blobs, redis also has lists, sets, etc. Redis stores everything in memory, so it is blindingly fast. Single thread, so just fire up multiple intsances if you've got more cores. Unlike memcached, you can persist it to disk. Replication is build-in. And it has client libraries for some 20 languages. Redis has build-in expiry. Just explicitly set the expiration time, no need to keep track of expiration yourself. Regarding lists, redis shows why it is more advanced than other non-datatype key/value stores: it supports pushing and popping at the begin and end of lists. You can use this for instance for showing recent events on some dashboard. Or a twitter-like timeline. To prevent these lists from becoming too big, you can tell redis to limit the length to a certain number. Now multiple clients can add items to the … -
Lightweight python deployment servers - Luit van Drongelen (PyGrunn conference)
He's mainly going to talk about uWsgi. He's especially not going to talk about apache :-) (Most in the audience were still using mod_wsgi + apache, btw). The reason he got involved with lightweight python servers as he's got a small hobby server only, so running apache with a couple of apps on a 256Mb memory server isn't fun. What's wrong with apache? By using ngnix for your static files you can easily double the response rate for a much lower memory usage than with apache. Ngnix can natively connect to uWsgi and apache cannot. uWsgi is fast and self-healing and sysadmin-friendly. It runs everwhere except on windows. It is more performant and has a lower memory footprint than mod_wsgi. Handy: it can handle multiple python interpreters, also in multiple virtualenvs. Very handy: it kills off misbehaving worker threads so that such a thread doesn't bring your entire server down. uWsgi can do more at the moment. It isn't wsgi-only anymore. It can handle long-running tasks for you if needed. If needed, you can run it with its own build-in webserver for testing purposes. And there's support for clustering. According to him, uWsgi has the best feature set of the … -
Practical project automation
I got a request for repeating an earlier talk about practical project automation at the PyGrunn conference. A conference in Groningen in the north of the Netherlands about python and related subjects. Sounded great, so I set out to update the talk. The basic structure could remain intact, as I'm still practicing what I preached at that older talk even though I'm at a new job right now. So it is really valid :-) Projects are more than just a collection of code. Projects are important. Projects are only finished when they're deployed. On the server so that the website is visible to the customer, for instance. Or installed on the customer's laptop. So one way or another you'll have to grab together all the pieces and install it somewhere. But you also have to do that yourself on your development laptop, right? And your colleagues, too. How many pages of instructions do you want to give to your colleagues? You'd better be automating this! And... automation helps heaps regarding quality. The cobbler's children go barefoot. We write software for our clients, but our own processes are non-automated manual and menial steps. Menial is bad, as it is boring. So … -
Class-based generic views and date evaluation in Django 1.3
Django 1.3 introduces class-based generic views as a replacement for function-based generic views. This new feature provides a more elegant solution to the long-standing issue of date evaluation in urls.py. -
I refuse to tolerate assholes
Rusty Russell — a hacker I admire greatly — writes: “If you didn’t run code written by assholes, your machine wouldn’t boot.” This was passed on to me by Ben Elliston, ex-gcc hacker and good guy. Amusing in context, but the corollary is that working on free software means you’ll encounter such people. You may have to work with them. You may have to argue with them (and they may be right). -
The Buddha Website wins two Webby Awards
I am excited to announce that The Buddha site won two Webby Awards! It was built in partnership with Sonnet Media as a companion to The Buddha documentary directed by David Grubin that aired on PBS in April 2010. The site was built using Django to create a multi layered interactive experience to further explore ... -
ST_Simplify(provided by PostGIS) and GeoDjango
ST_Simplify function is provided by PostGIS.It is used to simplify the geometry(eg. LINESTRING or POLYGON).It use `simplify` method of GEOSGeometry class.Django version is 1.3.>>> line_string.simplify?Type: instancemethodBase Class: <type 'instancemethod'>String Form: <bound method LineString.simplify of <LineString object at 0xa4ed5f0>>Namespace: InteractiveFile: /usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/gis/geos/geometry.pyDefinition: line_string.simplify(self, tolerance=0.0, preserve_topology=False)...>>> line_string<LineString object at 0xa4ed5f0>>>> len(line_string)4367>>> line_string[:3][(138.67654300000001, 35.492500999999997, 944.62300000000005), (138.676545, 35.4925, 944.62300000000005), (138.676546, 35.492499000000002, 944.63)]>>> simplified = line_string.simplify(0.001)>>> len(simplified)90>>> simplified2 = line_string.simplify(0.001, True)>>> len(simplified2)2458 -
AppHosted.com Django Hosting Service Review
This post is the fourth in my series about the new Django hosting services that just recently hit the market. Previously I have reviewed ep.io , gondor.io , and dotCloud.com .This post reviews AppHosted.com , another similar service that is currently in beta. I was lucky enough to get a sneak peak of this service before it was released to the general public, and here are my notes and impressions for the short time I had to play with the new service. Overview AppHosted.com uses a similar concept as the other django hosting services, they provide you with a command line client called metro that you use to interact with the service. Like the other command line clients, it is pretty much just a nice wrapper around their API, so anything you can do with the metro client you can do with their API. The client is used to configure your service and push your files up into their servers. Once the application is created and your code has been uploaded to their server, you can use their web based control panel to configure or manage your application. So that we can compare apples to apples I will go through … -
Django Job Opening @ CashStar.com (Portland, ME)
I work for a company called CashStar, most people have never heard of us, but a lot of people have used our products without even knowing it. CashStar is the man behind the curtain so to speak. We created an e-gift card platform that is used by some of the largest companies in the United States. Here is a short list of some of our customers: The Home Depot, Gap, Old Navy, Banana Republic, Staples, Coach, Starbucks, CVS, Chilis, Regal Cinemas, Pottery Barn, The CheeseCake Factory, Dell, Pizza Hut, and many more. To see the full list follow this link: http://www.cashstar.com/all-egift-card-clients/ Another thing that most people don't know is that we power that platform using the awesome python framework called Django. Using Python and Django, our small engineering team in Portland, Maine has taken our startup which didn't exist 3 years ago and turned it into a leader in the electronic gift card market. Due to this phenomenal growth, we need to expand our engineering team. We are currently looking for developers as well as QA folks to join our team. You will need to work on site in Portland Maine, and be legally allowed to work in the United … -
What is VPKG?
VPKG is a package manager for Django base web applications, that provide an easy way to managing current installed applications. The main idea behind the VPKG is to provide a dpkg like package manager for Vanda Platform and other web application that written using Django. Admin user can easily add a new application to the [...] -
Conference schedule posted
Conference schedule posted It has been a while and a lot has happened. We’re past due for an update! Talks The conference schedule has been finalized; we are proud to present an interesting program on a wide variety of Django subjects. You can now also submit entries for the lightning talks on the lightning talks page Waiting list The waiting list is full. Starting May 18th we will invite people who have subscribed to the waiting list on a first-come, first-served basis. We’re also pleased to announce that the higher “Night Owl” rate has been cancelled; the waitlist tickets will be sold at the standard conference rate. Sprints The Sprints are free for anyone to join. If you weren’t able to purchase a ticket but would love to spend some time with your fellow Djangonauts, the sprints are an excellent way of doing just that. If you plan on taking part in the sprints, please let us know via the sprint subscription page. If you’ve purchased tickets for the conference, you must still indicate that you’re staying for sprints by registering. Space at the sprint venue is limited, and we’d like to accomodate the maximum number of participants. Registering helps … -
Gunicorn on apache: zero length fix
I recently switched one of our django sites over from apache+mod_wsgi to apache(+mod_proxy)+gunicorn. The advantage of gunicorn is that every site runs in its own process instead of everything running within one apache. When a site barfs, you can at least see the culprit when you type "top". Oh, and the speed seemed higher. (For an introduction on gunicorn, see my summary of the gunicorn talk at last year's djangocon.eu). But today a colleague using IE8 couldn't load the PNG images. And in my log I'd get "connection reset by peer" errors out of gunicorn. I had no problems in firefox. Assumption: perhaps django's gzip middleware messes things up. I've seen gzip-related errors before. Never had a problem with it in django, but worth a try. So I disabled it. IE8 failed to work as before, but now also firefox didn't load the images. They came in as zero-length responses! The advantage: now I could debug it myself. I did a wget -S on the server itself to take a look at the headers as close to the site as possible. First a request to gunicorn running on port 10003 (some lines omitted as they're not relevant): Connecting to localhost|127.0.0.1|:10003... … -
South migrations for geospatial field types
I wanted to create a south migration for one of my django apps. An app with geospatial field types. Oops: $> bin/django schemamigration lizard_opendap --initial ! Cannot freeze field 'lizard_opendap.point.geom' ! (this field has class django.contrib.gis.db.models.fields.PointField) ! Cannot freeze field 'lizard_opendap.line.geom' ! (this field has class django.contrib.gis.db.models.fields.LineStringField) ! South cannot introspect some fields; this is probably because they are custom ! fields. If they worked in 0.6 or below, this is because we have removed the ! models parser (it often broke things). ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork Weird. I googled a bit and found out that support for those geom fields was added some years ago. So it should work. The solution: I forgot to add 'django.contrib.gis' to INSTALLED_APPS in settings.py. I thought that entry wasn't needed anymore, so I tend to leave it out. (Iirc, it used to be necessary because of geospatial databases, but those databases work just fine without adding django.contrib.gis to INSTALLED_APPS now). Yep, now it works: $> bin/django schemamigration lizard_opendap --initial + Added model lizard_opendap.Setting + Added model lizard_opendap.SourceModel + Added model lizard_opendap.Scenario + Added model lizard_opendap.ModelResult + Added model lizard_opendap.Point + Added model lizard_opendap.PointValue + Added model lizard_opendap.Line + Added model lizard_opendap.LineValue … -
Chef scripting quick start
This post is about Chef. Chef is a big odd but very powerful piece of software. You'll probably find it extremely useful for your deploy tasks - as soon as you can understand it. -
New house
Big news for us: if everything goes right, we'll be moving in one or two months! I never expected it to go this fast. We wanted a slightly bigger house in order to give both our kids (boy + girl) a separate room. So mostly the same size, but with one extra room. And a slightly bigger garden to house our bikes wouldn't hurt. Two months ago we started looking at houses for rent. In the Netherlands every region has a system of doling out houses from the so-called "social housing rental corporations". Based on the amount of time you wait. You can sign in on three houses per two weeks and the longest waiting time wins. That's how we got our current house. Aforementioned housing system only is allowed up until a certain income. We're above that margin, so we had to look for the more expensive rental houses that are handled outside the social rent system. The advantage: they're available earlier. The disadvantage: they're more expensive. Three weeks ago we subscribed ourselves at two housing agencies for rental houses. And I booked an appointment at a mortgage agent just in case it was possible for us to buy …