Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
New Year's Meme 2013
Inspired by Alex Clark's meme, here is my own entry into this end-of-year fun. What’s the Coolest Thing You Discovered This Year? Alex had his own focused on Python applications, frameworks, and libraries. Me, I'm going for a more general approach. This year I discovered: LaTeX That book I co-wrote with Audrey Roy? Written in LaTeX. It wasn't easy to get started, even with Audrey as my instructor, but now that I grok it, I feel extremely empowered. That's because I can do all kinds of awesome, insane hacks when Sphinx generates PDFs. I hope I get the chance to show off some of my new madness to the world in 2014. How to Tie A Bow Tie If you are going to be formal, the bow tie adds an enormous amount of class. However, clip-ons are considered tacky, especially as it's considered stylish to loosen the bow tie later in the evening to demonstrate you aren't wearing that clip. Of all the stuff I watched on the subject of bow tying, this video was the longest and the best of them all. Awesome Foods Around the World Here's the short-list: Oscypek is a Polish smoked, salted cheese that should … -
New Year's Meme 2013
Inspired by Alex Clark's meme, here is my own entry into this end-of-year fun. What’s the Coolest Thing You Discovered This Year? Alex had his own focused on Python applications, frameworks, and libraries. Me, I'm going for a more general approach. This year I discovered: LaTeX That book I co-wrote with Audrey Roy? Written in LaTeX. It wasn't easy to get started, even with Audrey as my instructor, but now that I grok it, I feel extremely empowered. That's because I can do all kinds of awesome, insane hacks when Sphinx generates PDFs. I hope I get the chance to show off some of my new madness to the world in 2014. How to Tie A Bow Tie If you are going to be formal, the bow tie adds an enormous amount of class. However, clip-ons are considered tacky, especially as it's considered stylish to loosen the bow tie later in the evening to demonstrate you aren't wearing that clip. Of all the stuff I watched on the subject of bow tying, this video was the longest and the best of them all. Update 1/4/2014: I learned this awesome skill because I wanted to be classy on my wedding day. … -
JavaScript based charts in Django made easy with Chartkick application
Chartkick is an application, a library for making JavaScript based charts. There is JavaScript library, Ruby wrapper and Python wrapper for Django and Flask. Let see what Chartkick can offer us in Django applications. -
Django blog tutorial - the next generation - part 1
My series of Django tutorials for building a blogging engine are by far the most popular posts I’ve ever written on here. I’ve had a lot of people contact me with questions or just to express their thanks, for which I’m very grateful! However, these tutorials haven’t really aged well. I’ve since had the opportunity to use Django in a professional capacity, which has significantly improved my understanding of the framework and the whole Python ecosystem, and there’s a lot of best practices that I didn’t follow and now wish I had. There’s also been a few gotchas that have hindered a few people in the past that I’d like to have the opportunity to correct. So, I’m therefore creating a brand new series of tutorials to remedy this situation. This series will cover exactly the same basic idea of using Django to build a blogging engine, but will expand on what the original series did in many ways. We will cover such additional topics as: Using Twitter Bootstrap to make your blog look good without too much hassle Using Virtualenv to sandbox your blog application Using South to effectively manage changes to your database structure Writing some simple unit … -
Euler Totient Function
In this post I will explain yet another simple number theoretic function, called the Euler Totient Function. This is a simple function which is used indirectly in many problems in programming contests. The function is denoted as phi(n). phi(n) basically gives the number of integers greater than 1 and lesser than n which are co-prime to the integer n. In other words, it is the cardinality of the set S = { a: 1<a<n , gcd(a,n) = 1 }. To calculate this function, we will use a straight forward brute force approach. With a simple analysis, we can show that the running time of this algorithm is O(sqrt(n)). - Start with an estimate of the totient function as n - Iterate for i from 2 to sqrt(n) - If i | n , we know that all factors of i less than equal to n will have gcd with n as atleast i. Hence, they can never be in the set S. Hence remove them from the result. - While i|n, divide n by i. - After the iteration of i from 2 to sqrt(n), if n is a number greater than 1, remove all its multiples less than n … -
How to Export Your Data as CSV, XLS, or XLSX
There are times, when you need to export the data from your database to different formats. For example, you want to create some diagrams in Office program for a presentation. In this post I will show you how to create admin actions which export selected items as files for a spreadsheet application (like MS Excel, OpenOffice Calc, LibreOffice Calc, Gnumeric, or Numbers). I will cover the mostly used formats: Comma Separated Values (CSV), Binary Excel (XLS), and Office Open XML (XLSX). First of all, have a look at the model we will be dealing with. It's a simple model with title, description, and - of course - the id. # models.pyfrom django.db import modelsclass MyModel(models.Model): title = models.CharField(max_length=100) description = models.TextField(blank=True) In the admininstration options, we'll define three admin actions: export_csv, export_xls, and export_xlsx. # admin.pyfrom django.contrib import adminfrom models import MyModel# ... export functions will go here ...class MyModelAdmin(admin.Admin): actions = [export_csv, export_xls, export_xlsx]admin.site.register(MyModel, MyModelAdmin) Now let's create functions for each of those actions! Comma-Separated Values Format CSV is the most common import and export format for spreadsheets and databases. It's a textual format which one could easily create or parse himself, but there is also a python built-in … -
Imaginary Realities is back
The Imaginariy Realities webzine was the place to go to for MUD game design articles in the late 90's. Last released in 2001, its articles are still worth the read for any game designers today. But guess what - this venerable ezine has now returned! You can find the new issue here.I think this is a good community initiative worthy of support. I contibuted two articles myself (one of which is about Evennia) and would like to thank the staff/editors who took their work very seriously and did sterling work on getting everything in shape.Thanks also to the other authors who penned some very interesting articles. Great job guys!My impressions: KaVir elaborates in A modern interface for a modern MUD on the advantages of not sticking with an outdated UI just for the sake of it. Adding a more accessible presentation is not that hard and won't ruin your game but rather help it. Whereas I have read his argument about this before, this is a good summary to take to heart. Evennia's javascript web client is currently mainly a telnet clone; there's a lot of things we could offer to make it easier for users to offer a more graphical … -
Start Your API - django-rest-framework part 1
In this video we start creating our API by learning what it takes to put data in our database, and retrieve it back doing all of our CRUD operations. django-rest-framework makes it very simple to accomplish with a minimal amount of effort.Watch Now... -
A note on Django 1.5.2 rotating CSRF token and frontend javascript applications
Django 1.5.2 introduced a change named The CSRF token now rotates when a user logs in. This isn't anything problematic for typical web applications where user submits a form and the page reloads. For applications that are based on JavaScript frameworks like ember (or angular) this becomes a problem, as the user is logged in the background with an AJAX request (for example with Facebook JS SDK) and the page in general never reloads. When he logs in the token changes and API (POST) requests (to django-rest-framework for example) will get forbidden as answers from the server. A solution would be to return a new token with server response to the login request and insert it in the place of the old one, which was inserter when Django template was rendered: xhr.setRequestHeader("X-CSRFToken", "{{csrf_token}}"); I wonder if there are any solutions for this already?.hll { background-color: #ffffcc } .c { color: #408080; font-style: italic } /* Comment */ .err { border: 1px solid #FF0000 } /* Error */ .k { color: #008000; font-weight: bold } /* Keyword */ .o { color: #666666 } /* Operator */ .cm { color: #408080; font-style: italic } /* Comment.Multiline */ .cp { color: #BC7A00 } … -
Working Together
Workflows, teams committing conflicting VCS branches, foreign keys being annoying and more feature in this week's Django Diaries. Time for your semi-regular update on how Django's migrations are going! I've implemented two major things since the last blog post: workflow improvements, and ForeignKey change detection. Workflow One of the problems that only started emerging with South some years after it was released was the issue of working with distributed VCS systems - like Git and Mercurial - and how their tendency towards branching impacted migration writing. When South was initially released, the world was mostly a Subversion place, and so the chance of two developers committing conflicting migrations was small. These days, the chance that someone is going to go off in a branch to add new model features while the master branch also gets a model bugfix is quite high. South didn't really deal with the resultant merge very well; it implicitly ordered migrations by filename, and so whoever had the migration which appeared first alphabetically "won"; the other developer would have to apply migrations out-of-order or back out theirs and then apply both. In short, it was a mess. My fix to this problem inside django.db.migrations is simple … -
Adding stacktraces to log messages
I always had this issue with libraries that logs useful stuff but make figuring out how you called said library very hard. For example, Django logs SQL queries but it's hard to figure out what code made the ORM query. This is a huge pain for Ajax requests - django-debug-toolbar can't help you much with those ... well, not yet. Turns out Python's logging module allows custom formatters. How about we write one ? The filter is just a class with a filter(record) method. It appears that filter can be called multiple times so we need to make sure we don't patch the record more than 1 time: class WithStacktrace(object): def filter(self, record): if not hasattr(record, 'stack_patched'): record.msg += " -- Stack: \n" + ''.join(format_stack(f=sys._getframe(1))) record.stack_patched = True return True You probably notice now the stacktrace can get rather long, and it includes useless frames from the logging module. We can fix that by blacklisting frames from logging or whatever we chose to ignore (like the django.db package): import sys from traceback import format_stack class WithStacktrace(object): def __init__(self, skip=(), limit=5): self.skip = [__name__, 'logging'] self.skip.extend(skip) self.limit = limit def filter(self, record): if not hasattr(record, 'stack_patched'): frame = sys._getframe(1) if self.skip: … -
Adding stacktraces to log messages
I always had this issue with libraries that logs useful stuff but make figuring out how you called said library very hard. For example, Django logs SQL queries but it's hard to figure out what code made the ORM query. This is a huge pain for Ajax requests - django-debug-toolbar can't help you much with those ... well, not yet. Turns out Python's logging module allows custom formatters. How about we write one? The filter is just a class with a filter(record) method. It appears that filter can be called multiple times so we need to make sure we don't patch the record more than 1 time: class WithStacktrace(object): def filter(self, record): if not hasattr(record, 'stack_patched'): record.msg += " -- Stack: \n" + ''.join(format_stack(f=sys._getframe(1))) record.stack_patched = True return True You probably notice now the stacktrace can get rather long, and it includes useless frames from the logging module. We can fix that by blacklisting frames from logging or whatever we chose to ignore (like the django.db package): import sys from traceback import format_stack class WithStacktrace(object): def __init__(self, skip=(), limit=5): self.skip = [__name__, 'logging'] self.skip.extend(skip) self.limit = limit def filter(self, record): if not hasattr(record, 'stack_patched'): frame = sys._getframe(1) if self.skip: while … -
How to Store Your Media Files in Amazon S3 Bucket
In this article, I will show you how to use Amazon Simple Storage Service (S3) to store your media files in the cloud. S3 is known and widely used for its scalability, reliability, and relatively cheap price. It is free to join and you only pay the hosting and bandwidth costs as you use it. The service is provided by Amazon.com. S3 tends to be attractive for start-up companies looking to minimize costs.S3 uses a concept of buckets which is like a storage database. Each bucket has its own url. Inside the buckets you have folders and under that you have files. In fact, directories don't actually exist within S3 buckets. The entire file structure is actually just one flat single-level container of files. The illusion of directories is actually created based on having the file names like dirA/dirB/file.If you want to browse the files in a folder-like structure, you can use Transmit FTP client on Mac OS X. It supports S3 services. Amazon browser-based console also has interface for browsing or uploading files.OK. Now let's have a look how to set up a Django project which will use S3 for media files. 1. Create a bucketAt first you will … -
Getting Started Contributing to Django
Recently I had the opportunity to attend the DjangoCon Sprint here in Chicago (see related post). One of my big take-aways from the event was that contributing to Django isn’t as daunting as I previously thought. The process is mostly straightforward and the Django team has gone a long ... -
Django Facebook 5.3
The 5.3 release makes it a lot easier to get started with Django Facebook. Documentation has had a major overhaul, many small bugs have been fixed and setting validation will complain if you make mistakes during the install. Have a look at the new docs. Especially the bit documenting how to use OpenFacebook will be interesting to many people: Getting an OpenFacebook object Making calls The full docs are linked on github. Share and Enjoy: -
Djangosites Open Sourced
I've been promising it for years, but never gotten around to it. Finally, I've pushed the source code for djangosites.org up to Github. -
Djangosites Open Sourced
I've been promising it for years, but never gotten around to it. Finally, I've pushed the source code for djangosites.org up to Github. -
Djangosites Open Sourced
I've been promising it for years, but never gotten around to it. Finally, I've pushed the source code for djangosites.org up to Github. -
Djangosites Open Sourced
Back in 2008 I started djangosites.org as a listing of websites powered by Django. Prior to that, we relied on a wiki page to see who was using Django, so an image-based website felt like a big improvement. Since day one I've promised to release the source code that I use for the site. It's relatively simple, so I never stressed much about making it a high priority - but I continue to be asked and politely berated for not getting it published. Today that's changed. I think it's too late for me to say I've come good on my promise, but the Djangosites source code is now available on GitHub. The README has more details, but in short this is a dump of the code currently running the site. I'll continue to use this repository as changes are made to the live site, however I'm not actively working on djangosites at this point in time (other than reviewing & approving submissions) There's a few pieces of this that might be useful for people new to Django, but otherwise this is really a collection of generic views. The useful bits might be: Full-text searching (and helper SQL) with PostgreSQL Generating … -
Djangosites Open Sourced
Back in 2008 I started djangosites.org as a listing of websites powered by Django. Prior to that, we relied on a wiki page to see who was using Django, so an image-based website felt like a big improvement. Since day one I've promised to release the source code that … -
Python Indie Bundle Cyber Monday Sale
I've joined forces with Matt Harrison and Audrey Roy to put together the first ever Python Indie Bundle sale! This bundle includes the following e-book bundles (PDF, Kindle, ePub) for just $24.95: Treading on Python Volume 1: Foundations Treading on Python Volume 2: Intermediate Two Scoops of Django: Best Practices for Django 1.5 Bought individually, these three books would cost you $36.95, but in honor of Cyber Monday we've chopped off about 33%, bringing you the awesome price of just $24.95! We're just indie authors who work without a publisher. We pay all the bills, do all the marketing, and make it or break it on our own. It's a lot of work, but we think the total control we have over our work speaks volumes for the quality of result. If you've been to my blog before, you probably already know about Two Scoops of Django that I co-wrote with Audrey Roy. However, you may not know about Matt Harrison's books, so I'm going to share some thoughts: Matt has a talent for explaining things related to Python. If you are still new to Python, his books will amplify your skills and get you to the next level. If … -
Python Indie Bundle Cyber Monday Sale
I've joined forces with Matt Harrison and Audrey Roy to put together the first ever Python Indie Bundle sale! This bundle includes the following e-book bundles (PDF, Kindle, ePub) for just $24.95: Treading on Python Volume 1: Foundations Treading on Python Volume 2: Intermediate Two Scoops of Django: Best Practices for Django 1.5 Bought individually, these three books would cost you $36.95, but in honor of Cyber Monday we've chopped off about 33%, bringing you the awesome price of just $24.95! We're just indie authors who work without a publisher. We pay all the bills, do all the marketing, and make it or break it on our own. It's a lot of work, but we think the total control we have over our work speaks volumes for the quality of result. If you've been to my blog before, you probably already know about Two Scoops of Django that I co-wrote with Audrey Roy. However, you may not know about Matt Harrison's books, so I'm going to share some thoughts: Matt has a talent for explaining things related to Python. If you are still new to Python, his books will amplify your skills and get you to the next level. If … -
Bagels
It’s impossible to get good bagels further west than about New Jersey, so I make my own. My recipe’s adapted from Baking Illustrated, Alton Brown’s pretzel recipe (yes pretzels, see below), and some techniques I learned at Wheatfields. There’s a few keys to making everything turn out right: Use the highest protein flour you can find. King Arthur Bread Flour is the best commonly available one you can find (at about 12-13% protein). -
To my friends in the Node community
Dear friends in the Node community, I’m excited and inspired by the work that you’re doing. Being new is exciting: you get to re-invent the world, and shape it to suit your purposes. You’re not bound by the mistakes other environments have accrued over the years. This has paid huge dividends. You’ve come up with a way to make asynchronous programming accessible to a much wider pool of programmers. You’re creating a set of tools that put developer experience first, proving that developer tools don’t have to have terrible user interfaces. -
Out-of-band mergings
As of today the development repository of Evennia, which has been brewing for a few months now, merged into the main repository. This update grew from one experimental feature to a relatively big update in the end. Together with the "many-character-per-player" feature released earlier, this update covers all the stuff I talked about in my Behind the Scenes blog post. Evennia's webserver was moved from Portal to Server. This moves all database-modifying operations into the same process and neatly avoids race conditions when modifying a game world from various interfaces. The OOB (Out Of Band) handler was implemented. This goes together with a protocol for telnet sub-negotiations according to the MSDP specification. The handler allows on-demand reporting whenever database fields update. It also offers regular polling of properties if needed. A user can customize which oob commands are available to the client and write whatever handlers are needed for their particular game. In the future we'll also add support for GMCP, but the lack of a central, official specification is off-putting (if there is a central document besides accounts of how individual games chose to implement GMCP, please let me know). For our own included web client, we'll likely just use …