Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Thread profiling in Python - Amjith Ramanujam
Amjith Ramanujam recently wrote a thread profiler in Python and it was rediculously simple. He works for New Relic, which is all about performance and expecially performance measuring. Python comes with batteries included, so it also includes a C profiler that works pretty well. But it doesn't work nice for django because the output is so huge. If you use the GUI RunSnakeRun, it is more managable that way. Additional problem with cProfile: it has about 100% overhead, so you can't run it in production (which they need). You can do more targeted profiling. For instance in Django. The way a web framework processes requests is normally always in the same way. You can use that during profiling. There are two important stages: interrupt and inquire. Interrupt A statistical profiler looks how often a function is called and by who. For this it needs to interrupt the regular process. You could set an OS-level signal to call your profiler every x miliseconds so that it can do something. It only works in linux, btw. Another way is to create a python background thread that wakes up every x miliseconds. It is cross-platform and mod_wsgi compatible. It is less accurate for … -
Combining Javascript and Django in a smart way - Przemek Lewandowski
Django is a javascript-agnostic web framework. Nothing is built-in so you can be up to date all the time. Javascript development moves very quickly. The basic approach is to include some custom inline javascript in the html pages. It quickly leads to illegible code that's hard to work on and hard to distribute. Javascript has frameworks, too. They give your application structure and take work off your hands. This is the advanced approach. It includes several parts: Communication with the server (REST api, websockets). Application building: combining and minimizing files. Static files management. Javascript improvements: coffeescript and so. What Przemek Lewandowski needed was a powerful javascript framework, coffeescript, testable code, js code minimization and fingerprinting for avoiding caches. And also rapid REST API development. Javascript framework They started with backbone, but it wasn't enough. They added marionette to backbone, but it still wasn't good enough. There's a lack of a binding mechanism; there are no reusable views; models are poor. AngularJS and Ember are better. Coffeescript It is controversial, but it helps to write code faster and use less code for it. It performs as well as javascript as it compiles to javascript. They used requireJS for painless coffeescript integration. … -
Migrating the future - Andrew Godwin
Andrew Godwin attempted to raise 2500 pounds for inclusion of south in Django core with kickstarter. It worked. In fact, he raised 17952 pounds! Why does South need to be replaced by a new version inside Django itself? It started 5 years ago, so there's 5 years of learning done in that period. Some things that made sense at the time aren't the best decision now. There's poor support for VCS branching. The migration files are huge. Migration sets get too large. There are projects with 1000 steps! The inside-django solution has two parts. The actual migration code and a separate backend. So if you want a different migration engine, you can probably reuse the backend code with its support for multiple types of databases. The new migration format is more declarative instead of imperative like it is now. This makes them smaller. It also allows you to compute the end result in memory and apply one single migration. Migrations will have a parent. So you won't have a problem with 0003_aaaa and 0003_bbbb migrations that halfway bite eachother. If a merge can be done automatically, fine, otherwise south/django will warn you. Squashing will be added. You can squash a … -
Djangocon lightning talks day 1
Sorry if I mangled any of the names, I took a photo of the lightning talk submission form and tried to decypher them :-) From carrots to Django - Kamila Stephiouska She tells about the Geek Girls Carrots community. A community for women interested in new technology. 11 cities, 4 special meetings, 1 sprint, 5 kinds of workshops. They like to promote women working in IT. The held a "django carrot" recently: 14 hours, 10 mentors, 23 participants. They try to get special guests. Last week Daniel and Audrey came (the writers of two scoops of Django). See http://django.carrots.pl They chose Django because of the community. Don't be afraid to commit - Daniele Procida Lots of people work with Django. Lots of people program with it. There are barriers to getting them to work on Django. They might not be effective. They might be afraid. They might not communicate effectively. You also need to manage your code and your environment. Virtualenv fixes the environment, but you need to learn that first. Version control helps with your code, but you first need to learn version control. Similarly, you need to learn documentation and tests. And you need to learn to have … -
Copernicus, the great refactorer - Brandon Rhodes
Brandon Rhodes mentions Nicolai Kopernik, a famous Polish scientist. He "lifted Earth into Heaven" by his book where he put the sun in the center of our universe instead of Earth. We're no longer at the bottom. The near-earth environment was pretty well mapped out. 300BC, the size of the spherical earth was already known. Around 100BC the distance to the moon was known. But what about those planets? They were harder. Stars did move around the sky more or less linearly. But those planets. They seemed to move back and forth a bit. Did they need to have a different model? The sun-centric model was already known, but it didn't catch on. The reason? Medieval science was too emperic: the earth cannot be moving, it seems to stay in place. Throw a ball and it falls down again towards the earth, it doesn't career off into space. The church wasn't totally idiotic by later convicting Galileo: there was just no solid emperical evidence :-) One of the pieces of evidence that was missing was that there was no observable stellar parralax; visible movement between stars because of earth movement. It was only in 1838 that the instruments were good … -
Query a Random Row With Django
Here's a gist for a drop-in Django manager class that allows you to return a random row. Model.objects.random() It can be used in your models.py like this: class QuoteManager(RandomManager): def random_filter(self): return self.filter(is_active=True) class Quote(models.Model): quote = models.TextField() by = models.CharField(max_length=75) is_active = models.BooleanField(default=True) objects = QuoteManager() def __unicode__(self): return self.by Advantages over using the order_by('?') is performance. Random sort at the database seems to be extremely slow on most databases even if the table only has a few thousand rows. Note that the count of records is cached for 5 minutes, so if the table changes often you may want to change that. A limitation is that it only returns one row. -
Installing Django on Ubuntu memo
Here are a few notes and links after moving to the new Ubuntu server on linode.com. Some steps for security: My First 5 Minutes On A Server Install packages: 1 2 3 4 apt-get install apache2 libapache2-mod-wsgi apt-get install postgresql postgresql-server-dev-9.1 python-dev apt-get install mysql-server mysql-common mysql-client libmysqlclient-dev apt-get install git git-core Setup virtualenv: 1 2 3 4 apt-get install python-setuptools apt-get install python-pip pip install virtualenv virtualenv --no-site-packages /path/to/venv Install PIL in virtualenv: 1 2 3 4 5 apt-get install libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/ ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/ ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/ pip install PIL Enable apache mods: 1 2 a2enmod rewrite a2enmod expires Configs for Django apps: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 /path/to/site/app/wsgy.py import os import sys sys.path.append('/path/to/env/lib/python2.7/site-packages') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() /etc/apache2/sites-available/site.conf <VirtualHost *:80> ServerName site.com ServerAlias www.site.com ServerAdmin admin@site.com DocumentRoot /path/to/site/ WSGIDaemonProcess site.com processes=2 … -
I've joined Heroku
I’ve joined Heroku as their Director of Security. Why? I started as a Heroku skeptic. The first iterations of Platform-as-a-Service left me deeply underwhelmed. “Deploying web apps is hard,” I said, “there’s no way you can just abstract it away like that.” I was wrong. Over the last few years I’ve gone from being a Heroku skeptic, to a user, to a fan, and now — an employee. Perhaps at some later point I’ll write a bit about how my thoughts evolved, but for now I’ll leave it at this: Heroku’s vision of a world where developers are empowered to deliver apps is one I support. -
One to Many
As of yesterday, I completed and merged the first of the three upcoming Evennia features I mentioned in my Churning Behind the Scenes blog post: the "Multiple Characters per Player" feature.Evennia makes a strict division between Player (this is an object storing login-info and represents the person connecting to the game) and their Character (their representation in-game; Characters are just Objects with some nice defaults). When you log into the game with a client, a Session tracks that particular connection.Previously the Player class would normally only handle one Session at a time. This made for an easy implementation and this behavior is quite familiar to users of many other mud code bases. There was an option to allow more than one Session, but each were then treated equally: all Sessions would see the same returns and the same in-game entities were controlled by all (and giving the quit command from one would kick all out).What changed now is that the Player class will manage each Session separately, without interfering with other Sessions connected to the same Player. Each Session can be connected, through the Player, to an individual Character. So multiple Characters could in principle be controlled simultaneously by the … -
Enabling CORS in Angular JS
I was recently experimenting with building an API with django-tastypie and make it accessible via CORS, so it can be used from a different host from an AngularJS app. For the Django part it was relatively straightforward. I could have either written my own Middleware, dealing with incoming CORS requests, but decided to use django-cors-headers in the end. Following the instructions in the github repo and adding my host where AngularJS is hosted to the CORS_ORIGIN_WHITELIST setting did enable the Django server to handle CORS. With AngularJS it was a little more tricky, mainly because information is spread all over the web. Beside the fact that I was trying to implement a service using ngResource to communicate with the API, the following did enable AngularJS to send its requests with the appropriate CORS headers globally for the whole app: var myApp = angular.module('myApp', [ 'myAppApiService']); myApp.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; } ]); _ Just setting useXDomain to true is not enough. AJAX request are also send with the X-Requested-With header, which indicate them as being AJAX. Removing the header is necessary, so the server is not rejecting the incoming request. -
Django Facebook – 1.5 and custom user model support
Django Facebook now officially supports Django 1.5 and custom user models! Go try it out and upgrade to pip version 5.1.1. It’s backwards compatible and you can choose if you want to keep on using profiles, or migrate to the new custom user model. Installation instructions can be found on github. Contributing Thanks for all the contributions! My startup (Fashiolista) depends on a reliable Facebook integration and maintaining it would not be possible without all the pull requests from the community. Contributions are strongly appreciated. Seriously, give Github a try, fork and get started :) About Django Facebook Django Facebook enables your users to easily register using the Facebook API. It converts the Facebook user data and creates regular User and Profile objects. This makes it easy to integrate with your existing Django application. I’ve built it for my startup Fashiolista.com and it’s currently used in production with thousands of signups per day. For a demo of the signup flow have a look at Fashiolista’s landing page (fashiolista.com) After registration Django Facebook gives you access to user’s graph. Allowing for applications such as: Open graph/ Timeline functionality Seamless personalization Inviting friends Finding friends Posting to a users profile Django Facebook … -
The Easy Form Views Pattern Controversy
This isn't a controversy 'per se', except perhaps in the feverish depths of my brain. In the summer of 2010 Frank Wiles of Revsys exposed me to what I later called the "Easy Form Views" pattern when creating Django form function views. I used this technique in a variety of places, including Django Packages and the documentation for django-uni-form (which is rebooted as django-crispy-forms). At DjangoCon 2011 Miguel Araujo and I opened our Advanced Django Forms Usage talk at DjangoCon 2011 with this technique. It’s a pattern that reduces the complexity of using forms in Django function-based views by flattening the form handling code. How the Easy Form Views pattern works Normally, function-based views in Django that handle form processing look something like this: def my_view(request, template_name="my_app/my_form.html"): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): do_x() # custom logic here return redirect('home') else: form = MyForm() return render(request, template_name, {'form': form}) In contrast, the Easy Form Views pattern works like this: def my_view(request, template_name="my_app/my_form.html"): form = MyForm(request.POST or None) if form.is_valid(): do_x() # custom logic here return redirect('home') return render(request, template_name, {'form': form}) The way this works is that the django.http.HttpRequest object has a POST attribute that defaults to … -
The Easy Form Views Pattern Controversy
In the summer of 2010 Frank Wiles of Revsys exposed me to what I later called the "Easy Form Views" pattern when creating Django form function views. I used this technique in a variety of places, including Django Packages and the documentation for django-uni-form (which is rebooted as django-crispy-forms). At DjangoCon 2011 Miguel Araujo and I opened our Advanced Django Forms Usage talk at DjangoCon 2011 with this technique. It’s a pattern that reduces the complexity of using forms in Django function-based views by flattening the form handling code. How the Easy Form Views pattern works Normally, function-based views in Django that handle form processing look something like this: def my_view(request, template_name="my_app/my_form.html"): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): do_x() # custom logic here return redirect('home') else: form = MyForm() return render(request, template_name, {'form': form}) In contrast, the Easy Form Views pattern works like this: def my_view(request, template_name="my_app/my_form.html"): form = MyForm(request.POST or None) if form.is_valid(): do_x() # custom logic here return redirect('home') return render(request, template_name, {'form': form}) The way this works is that the django.http.HttpRequest object has a POST attribute that defaults to an empty dictionary-like object, even if the request’s method is equal to "GET". Since we … -
Stonewall Jackson and documentation
Today it is 150 years ago that Stonewall Jackson died. Not everyone will recognize the name: it is a general from the American civil war. And a good one at that! Bear with me, I'll have a programming-related comment to make on documentation :-) If you know a bit about the second world war, you might have heard about the German general Erwin Rommel. Jackson's fame was a bit like that. If you had to fight Jackson or Rommel, it didn't really matter that you had more men and equipment: he'd beat the crap out of you anyway. Once at a time Jackson's 15000 men ran circles around 60000 opponents and repeatedly beat them. That's 1:4. And they won. Both Jackson and Rommel seemed to have a Fingerspitzengefühl. They'd known instinctively when to do or not do something. When to lay in wait and when to strike out despite the odds. Both also seemed to be one-of-a-kind. I mean it in the sense that they could not teach others to do the same. It was all in their own head. It was all dependent upon them. And at least Jackson didn't tell anything to his subordinates; he was secretive. When … -
Starting Off
Welcome to the first of my Django Diaries, where I'll be detailing the progress I'm making on my Schema Alteration project. After a very successful Kickstarter, I had the unfortunate situation of a couple of successive trips abroad, and so initial work has been a bit more delayed than I would have liked. However, thanks to securing more time to work on the project every week, progress should be faster than planned from now on. The plan is that these diaries will contain a rough summary of the work I've been doing; they're here both to help engage you (the slightly-too-interested public) in the work I'm doing, as well as providing some transparency of the work I'm doing. If you want to hear more about a certain issue, feel free to get in touch with me - see the About page for my contact details. I'd love to explain as much as I can to those who are interested! Laying the Groundwork The first task I faced was to go back to my original Django branch and get it up-to-date with the changes in trunk. The only change that affected the schema work was Aymeric Augustin's transaction changes - he's … -
Making Django play nicely with AngularJS
Introduction During the development of a new feature to allow users to "pin" content to read at a later date, we came up against the age-old problem in our application - how to write javascript without a whole heap of boilerplate. We've tried various approaches in the past, e.g. using Handlebars to template data received from the server, and wrapping up some repeated operations in some hand-rolled "libraries". We'd chosen not to use a javascript framework previously since jQuery is a pretty powerful tool which could be used to meet most of our needs since our application consists of many pages which require a small degree of progressive enhancement and not a full-blown client-side application. This pinning challenge was a bit different from problems we'd come across before since there would be a pins widget on almost every page in the site and any page that contained our editorial or user-contributed content would be eligible for a pinning control, so we decided that it was the right time to choose a framework, even if it were one with a fairly minimal feature-set for wrapping some low-level operations. Why AngularJS? We identified several things which cause us irritation and slow us … -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you’ve transitioned from … -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you've transitioned from old... -
Upgrades: Django Old to Django New
Upgrades: Making the Jump from Django Old to Django New Sometimes we are faced with the challenge of upgrading old Django-based projects. The task can be daunting, as a lot has happened in Django within the last few years. Since Django 1.1.1, Django has been through 15 micro ... -
Making Django 1.5 compatible with django-bcrypt
Last night I took the opportunity to upgrade all of getsentry.com to Django 1.5. While most things were fairly trivial to sort out, we hit one less obvious (and pretty critical) bug during the migration surrounding django-bcrypt. This bug would only present itself if you've transitioned from old... -
Einladung zur Django-UserGroup Hamburg am 08. Mai
Das nächste Treffen der Django-UserGroup Hamburg findet am Mittwoch, den 08.05.2013 um 19:30 statt. Dieses Mal treffen wir uns wieder in den Räumen der intosite GmbH im Poßmoorweg 1 (3.OG) in 22301 Hamburg. Die Organisation der Django-UserGroup Hamburg findet ab jetzt über Meetup statt. Um automatisch über zukünftige Treffen informiert zu werden, werdet bitte Mitglied in unserer Meetup-Gruppe: http://www.meetup.com/django-hh Da wir in den Räumlichkeiten einen Beamer zur Verfügung haben hat jeder Teilnehmer die Möglichkeit einen kurzen Vortrag (Format: Lightning Talks oder etwas länger) zu halten. Konkrete Vorträge ergeben sich erfahrungsgemäß vor Ort. Eingeladen ist wie immer jeder der Interesse hat sich mit anderen Djangonauten auszutauschen. Eine Anmeldung ist nicht erforderlich, hilft aber bei der Planung. Weitere Informationen über die UserGroup gibt auf unserer Webseite www.dughh.de. -
New Committers for Tastypie & Haystack
New Committers for Tastypie & Haystack -
Tools we used to write Two Scoops of Django
Because of the ubiquitousness of reStructuredText in the lives of Python developers and the advocacy of it, it's not uncommon for people to assume we used it to write our book. However, that's not really the case. The short Answer is we used: reStructuredText (RST) Google Documents Apple Pages LaTeX The long answer is the rest of this posting. Since writing the book was broken up into three major stages 'alpha', 'beta', and 'final', so have I broken up blog article. Alpha Days Some of the original alpha material was written in rough draft form as RST since it was what we were used to using. Unfortunately, the PDF generation wasn't to our liking, so we immediately began looking at other options. Since she enjoyed using it at MIT and because it gave us greater individual control, Audrey wanted to switch to LaTeX. I was worried about the challenges of learning LaTeX, so we compromised and moved to Google Documents. For the most part, Google Documents was great in the early stages. The real-time collaborative nature was handy, but the gem was the comment system. It gave us the ability to have line-by-line written dialogues with our technical reviewers. However, … -
Tools we used to write Two Scoops of Django
Because of the ubiquitousness of reStructuredText in the lives of Python developers and the advocacy of it, it's not uncommon for people to assume we used it to write our book. However, that's not really the case. The short answer is we used: reStructuredText (RST) Google Documents Apple Pages LaTeX The long answer is the rest of this posting. Since writing the book was broken up into three major stages 'alpha', 'beta', and 'final', so have I broken up blog article. Alpha Days Some of the original alpha material was written in rough draft form as RST since it was what we were used to using. Unfortunately, the PDF generation wasn't to our liking, so we immediately began looking at other options. Since she enjoyed using it at MIT and because it gave us greater individual control, Audrey wanted to switch to LaTeX. I was worried about the challenges of learning LaTeX, so we compromised and moved to Google Documents. For the most part, Google Documents was great in the early stages. The real-time collaborative nature was handy, but the gem was the comment system. It gave us the ability to have line-by-line written dialogues with our technical reviewers. However, … -
Box Office Champs Launches
A fantasy movie game built using Django. This is a very easy game where you pick the 15 movies you think will be the highest grossing movies of the season. You can create a group and compete with your friends. You should give the site a try today. Iron Man 3 opens tomorrow and you definitely want to have that movie on your roster. Unlike fantasy sports, you can play this game 4 times a year. The summer season starts tomorrow. Kudos to Rudy Menendez who did principal development and game design and Noah Wenz for design and HTML. The site was with spare time over the last few months. Put together, development time was about 2-3 weeks. If you need a fantasy site done, contact Ed or Rudy Menendez and we can help you out.