Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Creating modern web applications with Django and ember.js JavaScript framework
emberjs is a new JavaScript framework for building interactive/responsive web applications. Compared to "classical" approach it removes the need to write code for AJAX requests fetching, modifying data or for example code responsible for DOM manipulation. Like in good framework we write only the code implementing our app functionality/idea. emberj.js is quite a young project so the amount of tutorials isn't high nor the documentation isn't of Django level - but still it's there and it's not that bad. At the moment Ember is close to reaching the 1.0 release and it's quite stable allowing real production application development. In the same category we can also find other similar frameworks like Backboje.js or Angular.js. Each has its strong and weak points. In this article I'll showcase basic ember features and ember application development process for a Django-Tastypie-Ember application. You need at least basic Django and django-tastypie (REST API-making application for your models). The whole application developed in this article can also be downloaded and launched on your localhost. -
Django Extensions 1.1.0
We just released version 1.1.0 of Django-Extensions. This version brings initial support for both Django 1.5 and Python 3.3 ! Thanks to fhahn and Mikolaj Romel for their help on this. ChangeLog: Python 3.3 support Django 1.5 support PACKAGING: Added license file to source distribution FEATURE: Add pipchecker command for reporting out-of-date requirements FEATURE: Allow to set uuidfield max_length FEATURE: dumpscript got hooks to override save and locate calls FEATURE: notes command now also support WARNING and NOTE annotations FEATURE: shell_plus command now support settings SHELL_PLUS variable in settings file which indicated with interactive python shell to use. DOCS: Fixed documentation which was messing up the table of content. FIX: Added empty migration to make south happy :) FIX: UUID never appears on admin form FIX: reset_db would set OWNER = None when executed without db user FIX: shell_plus disabled using pythonrc per default. -
We are not using PayPal
In January Audrey Roy and I launched a book about Django called Two Scoops of Django: Best Practices for Django 1.5. We decided to not use PayPal. Here's why: Open Source Events Get Burned By PayPal PayPal has a long, sordid history of freezing the accounts of Python related conferences and events around the world. In fact, this article was born out of the fact DjangoCon Europe 2013 had its PayPal account frozen. In the past, DjangoCon Europe 2012, Plone Conferences 2008, 2011, and at least one PyCon Australia dealt with the same PayPal problem (DjangoCon 2013 was forewarned and took measures to protect itself). We also have unconfirmed reports of other Python and Django events also running into problems with PayPal freezing accounts. Going with just confirmed conferences having issues with PayPal, this is a combined total of assets in excess of over US$100,000 dollars. It's not just a Python issue either, it's an issue that strikes other open source languages and tools. It's at the point now where conference organizers don't trust PayPal and make a point telling each other to use alternative payment gateways. Fear, Shame, and PayPal The terrifying thing to consider is that I suspect … -
We are not using PayPal
In January Audrey Roy and I launched a book about Django called Two Scoops of Django: Best Practices for Django 1.5. We decided to not use PayPal. Here's why: Open Source Events Get Burned By PayPal PayPal has a long, sordid history of freezing the accounts of Python related conferences and events around the world. In fact, this article was born out of the fact DjangoCon Europe 2013 had its PayPal account frozen. In the past, DjangoCon Europe 2012, Plone Conferences 2008, 2011, and at least one PyCon Australia dealt with the same PayPal problem (DjangoCon 2013 was forewarned and took measures to protect itself). We also have unconfirmed reports of other Python and Django events also running into problems with PayPal freezing accounts. Going with just confirmed conferences having issues with PayPal, this is a combined total of assets in excess of over US$100,000 dollars. It's not just a Python issue either, it's an issue that strikes other open source languages and tools. It's at the point now where conference organizers don't trust PayPal and make a point telling each other to use alternative payment gateways. Fear, Shame, and PayPal The terrifying thing to consider is that I suspect … -
Welcome to the world django-fancy-cache!
A Django cache_page on steroids Django ships with an awesome view decorator called cache_page which is awesome. But a bit basic too. What it does is that it stores the whole view response in memcache and the key to it is the URL it was called with including any query string. All you have to do is specify the length of the cache timeout and it just works. Now, it's got some shortcomings which django-fancy-cache upgrades. These "steroids" are: Ability to override the key prefix with a callable. Ability to remember every URL that was cached so you can do invalidation by a URL pattern. Ability to modify the response before it's stored in the cache. Ability to ignore certain query string parameters that don't actually affect the view but does yield a different cache key. Ability to serve from cache but always do one last modification to the response. Incrementing counter of every hit and miss to satisfy your statistical curiosity needs. The documentation is here: https://django-fancy-cache.readthedocs.org/ You can see it in a real world implementation by seeing how it's used on my blog here. You basically use it like this:: from fancy_cache import cache_page @cache_page(60 * 60) def … -
Two Scoops of Django 1.5 Beta Released
After thirty four days of hard work, Audrey Roy and I are proud to announce that we've released the beta of Two Scoops of Django: Best Practices for Django 1.5. It's been a monumental effort, a labor of love, and we hope you find our efforts worthy. You can buy it right now in e-book (PDF) form on the website: http://django.2scoops.org Two Scoops of Django: Best Practices for Django 1.5 is a compilation of best practices for the Django framework. Like any framework, Django has tips, tricks, and pitfalls that aren't documented in one place. Experienced developers know this stuff, but gleaning it off the Internet takes a lot of time. We decided to take everything we know and write it down. We stand of the shoulders of giants: We received advice from Django experts including a BDFL, Django core developers, and subject matter experts from around the world. Reader contributions from advanced and beginning developers have also shaped the book, and we can't thank enough those who gave us their insights. What is different about the beta release? Added 50+ pages of content while reducing the file size from 5.1 MB to 1.5 MB. Added list of tables, list … -
Two Scoops of Django 1.5 Beta Released
After thirty four days of hard work, Audrey Roy and I are proud to announce that we've released the beta of Two Scoops of Django: Best Practices for Django 1.5. It's been a monumental effort, a labor of love, and we hope you find our efforts worthy. You can buy it right now in e-book (PDF) form on the website: http://django.2scoops.org Two Scoops of Django: Best Practices for Django 1.5 is a compilation of best practices for the Django framework. Like any framework, Django has tips, tricks, and pitfalls that aren't documented in one place. Experienced developers know this stuff, but gleaning it off the Internet takes a lot of time. We decided to take everything we know and write it down. We stand of the shoulders of giants: We received advice from Django experts including a BDFL, Django core developers, and subject matter experts from around the world. Reader contributions from advanced and beginning developers have also shaped the book, and we can't thank enough those who gave us their insights. What is different about the beta release? Added 50+ pages of content while reducing the file size from 5.1 MB to 1.5 MB. Added list of tables, list … -
Concurrent Python (AWPUG talk resources)
I'm doing a concurrency/gevent talk tonight at the Austin Web Python User Group. Slides and other resources are available here. Slides iPython Notebook gevent For the Working Python Developer A Curious on Coroutines and Concurrency, by David Beazley Concurrency is not Parallelism, by Rob Pike gevent gevent 1.0 downloads gevent-spider (recursive web-based web spider) Collaborative painting app source -
Using github pull requests inside a company
A couple of months ago I read an article about effective pull requests for teams. The article made me want to use pull requests inside our company (Nelen & Schuurmans), too. I myself only started using pull requests a lot a few weeks ago, when writing pull requests for zc.buildout. Make a branch, work on a feature, push the branch, open a pull request. The good thing about a pull request on github is that you can easily give feedback. Me and a few others started working with pull requests at our company. We decided to just start doing it "as it is good to do it". There's no sense in having meetings to tell everyone to do it: it has to grow into the team's common work process. So... yesterday, for example: I cooked up a small fix on a branch and pushed it to github. I created a pull request out of it on github. I went to a colleague's desk and asked him to quickly review it now (as I really needed it quickly). I got a comment ("no hardcoded admin url, use a reverse admin url"). Yep, I normally omit that step. Good to get feedback … -
Pypi and externally-hosted distributions
There's a whopping huge discussion on Python's catalog-SIG mailinglist about deprecating external links on PyPI (the Python Package Index). What is the problem? Well, my colleague has this now: $ pip install mercurial Downloading/unpacking mercurial ^C^C^C^C An endless wait for downloading mercurial from PyPI. Bad PyPI, right? No, actually not. Pip (or buildout) looks at http://pypi.python.org/simple/Mercurial/ This page is full of download URLs like http://mercurial.selenic.com/release/mercurial-1.6.3.tar.gz . Which have been failing for a couple of hours now because currently the mercurial website is down (it will probably be up again if you read this later). What I want to see is PyPI-hosted download links like http://pypi.python.org/packages/source/z/zest.releaser/zest.releaser-3.27.tar.gz#md5=f670b3b35b6a4e432fc97fc9659e95df . PyPI reliability has been really good lately. But if you have a PIP requirements file or a buildout with many dependencies, two or three of those dependencies will be on external non-PyPI servers, like mercurial's. So instead of the reliable PyPI, you now have three servers that can be down... Andreas said it best: I give a shit at the arguments pulled out every time by package maintainers using PyPI only for listing their packages. Some arguments might be valid, but these projects are, taken as one group, actively breaking pip and buildout regularly. … -
Django 1.5 ya está aquí
Se acaba de lanzar Django 1.5. La nueva versión incluye interesantes mejoras decritas en las release notes. Éstos son algunos de los aspectos más destacados: Django 1.5 introduce soporte para un modelo de usuario configurable. El modelo básico de usuario de Django sigue presente, pero ahora el framework soporta especificar nuestro propio modelo y que el sistema de autenticación de Django la use. Django 1.5 es la primera versión de Django con soporte para Python 3 (específicamente, Python 3.2 y posteriores). El soporte para Python 3 todavía se considera experimental, pero hay disponible una guía para portar nuestro código a Python 3 y los bugs de compatibilidad con Python 3 se considerarán bloqueantes para futuras versiones... -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia’s first ever PyCon. If you’re not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It’ … -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia's first ever PyCon. If you're not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It's not often I g... -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia's first ever PyCon. If you're not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It's not often I g... -
Djangocon.eu in Warsaw: I'm coming!
Yeah, I booked my ticket this afternoon. I'm in! The final batch (40% of the tickets) went on sale at 16:00 CET and our secretary got my ticket in at 16:05, except that my boss's credit card didn't work. So I had to grab my own, but I'm in. I'm happy that the company that I work for (Nelen & Schuurmans) pays for my ticket. Going to a conference is an essential part of keeping my knowledge up-to-date. I told them that during my job interview. That's actually a funny story. I'm a civil engineer by education, so I don't have an official IT background. Lots of experience, but no official IT education. So the second question I got during my job interview was something like: we were actually looking for a real solid IT programmer and now we're getting a civil engineer again. We already have one :-). So... how do you learn? How do you keep your knowledge up to date? I liked the question. I had no problem pointing at my experience (which they knew about: of course they googled me beforehand). And what about learning and keeping my knowledge up-to-date? Well, two things, I answered: Reading … -
Django: Log and block brute force attempts
Here is a very simple mechanism for wrapping a decorator around your views to protect them against brute force attempts. For instance, if you have a secret file download available only with the right secret (/view/id/secret-hash/), you expose your view to simple brute force attempts. Simply put, this decorator will log a 404 response object or Http404 exception, count pr. IP and return status=400 and send you an email whenever a new block is put into place. Model class IllegalLookup(LogModifications): """Log and block illegal lookups""" created = models.DateTimeField( verbose_name=_(u'created'), auto_now_add = True, ) modified = models.DateTimeField( verbose_name=_(u'created'), auto_now = True, ) ip_address = models.CharField( max_length=16, null=True, blank=True, verbose_name=_(u'IP address'), ) path = models.CharField( max_length=255, null=True, blank=True, verbose_name=_(u'path'), help_text=_(u'First attempted path is always logged'), ) count = models.PositiveIntegerField( default=1, ) @classmethod def log_lookup(cls, ip_address, path): try: now = timezone.now() expired = now - timedelta(minutes=settings.BLOCK_EXPIRY) lookup = cls.objects.get(ip_address=ip_address, modified__gte=expired) lookup.count += 1 lookup.save() except cls.DoesNotExist: # Delete old entries first cls.objects.filter(ip_address=ip_address).delete() lookup = cls.objects.create(ip_address=ip_address, path=path) lookup.save() @classmethod def is_blocked(cls, ip_address): try: now = timezone.now() expired = now - timedelta(minutes=settings.BLOCK_EXPIRY) lookup = cls.objects.get(ip_address=ip_address, modified__gte=expired) if lookup.count == settings.BLOCK_ATTEMPTS: mail_admins("IP blocked", "{0} is now blocked, IllegalLookup id: {1}".format(ip_address, lookup.id)) if lookup.count > … -
Using Django flatpages content in other (class-based) views
The flatpages application that ships with Django is both (intentionally) simple and useful. In previous projects I’ve found myself both extending the models (to add data like meta tags) and duplicating the whole application (when I wanted to add a whole bunch of extra details, multiple content sections, or a WYSIWYG editor). In a recent project I had the need to editable (by administrators) content in other views, and I turned to flatpages again for my solution. What I did was to create a class-based view mixin to find the flatpage for a given URL (defaulting to the one defined in request.path), and include the resulting object in the context (once the title and content had been marked safe of course): from django.contrib.flatpages.models import FlatPage class FlatPageMixin(object): """ Retrieves the FlatPage object for the specified url, and includes it in the context. If no url is specified, request.path is used. """ url = None def get_context_data(self, **kwargs): if not self.url: self.url = self.request.path context = super(FlatPageMixin, self).get_context_data(**kwargsG) try: flatpage = FlatPage.objects.get(url=self.url) flatpage.title = mark_safe(flatpage.title) flatpage.content = mark_safe(flatpage.content) context["flatpage"] = flatpage except FlatPage.DoesNotExist: context["flatpage"] = None return context Then you just need to ensure a flatpage exists for the expected (or … -
Better UI prototyping with a Django twist
As part of our new appreciation for start-up organizations and their love of Django, we thought we’d share how we approach the concept of rapid UI prototyping.Early stage start-up companies often need a proof of concept to help convey the vision of the new business model. Yes, there ... -
Team Django Update
Reflections on my Progess Team Django is progressing nicely so far. We have provided a variety of contributions to Django. If you proceed to our Contributions page on the team wiki can you view each contribution. So far the team has contributed 4 documentation changes, one bug report, and fixed a bug and provided a regression test for the fix. I feel the team is working well together, and I am content with our current progress. Not to say areas could not be improved, but that is the nature of all things. As we progress we are attempting to increase the difficulty in the scale of our contributions, so I am unsure if the current progress will be maintained. To ease the transition to tackling more difficult tickets, team members will need to have a better understanding of the Django codebase.Thus I am proposing we read through the code and focus on the unit tests. Yes, I did say focus on the unit tests. As one of the hosts pointed out in the 25th episode of Programming Throwdown, well written unit tests serve as great documentation of the program's code. So by reading through unit tests, developers new to the … -
Nice Django sprint in Utrecht
Last weekend I joined in the world wide Django sprint. Nice! I went to Utrecht (NL), which is just half an hour from my doorstep :-) We could use the offices of the Dutch game garden for free, for they want to support initiatives like a Django sprint. It was a nice place in a former bank office right in the center of Utrecht. On saturday some 50 people attended, on sunday 25 (both my estimate). Three core committers were there: Jannis Leidel, Aymeric Augustin and Florian Apolloner. That's really a tip when you're organizing a sprint: get one or more core committers on board for questions, tips and for the occasional nudge to accept pull requests. It just makes the whole process work much smoother. By design, Django's community process is pretty much centered on the double handful of active core committers (at least to my eyes; by comparison I'm used to 80 committers to the core Plone code). For me, getting to know a couple of people better (amongst them two core committers I hadn't met that way) was the highlight of the weekend. Github talks about "social coding": they really have a point. Don't underestimate the social … -
The restful Marketplace
While the Firefox Marketplace is being built, we are starting to make some fundamental changes in the way the Marketplace is constructed behind the scenes. In the beginning there was one big Django site that served all the requests back to the users. Over the course of the last few months that has changed to being a smaller number of services that provide APIs to each other. We’ve got separate services for payments (and this), statistics (and this) and a new front end client and plans for more. The main communication mechanism between them is going to be REST APIs. For REST APIs in Django we are currently using Tastypie, which does a pretty good job of doing a lot of things you’d need. There are a few frustrations with Tastypie and going forward I’m extremely tempted by Cornice, which we currently use for statistics. When you ask people about consuming REST APIs in Python, lots of people tell me “we just use requests“. Requests is a great library for making HTTP calls, but when you are developing against a REST API having all the overhead of coping with HTTP is a bit much. Coping with client errors versus HTTP … -
Django staticfiles documentation
At the Django sprint in Utrecht (NL), I'm working on the Django staticfiles documentation (see ticket 19582). To get my own thoughts sorted out, I'm trying to rewrite the existing HOWTO here in this blog entry :-) Very short, of course. Mostly to figure out a working structure. A funny thing happened when writing it: I learned new things. We're sprinting on the staticfiles docs with four people and each one sees different new things. I personally didn't know the {% static "app/logo.png" %} template tag existed to help you with custom backends. And I did take a look at those custom storage backends at the same time as I hadn't really looked at them before. Anyway, here's a short howto on Django's staticfiles: Managing static files (css, javascript, jpg) Your website will probably include images and css files. Django provides django.contrib.staticfiles to help you manage them. Note: the term static files differentiates them from the files that are uploaded to your site (though FileField, for instance). Those uploaded files are called media files. You'll see the difference in some of the settings. Using django.contrib.staticfiles By default, Django looks for static files in directories called static/ inside your apps and … -
Getting vagrant box networking working again after wifi change
I'm using vagrant for my osx python/django work. There's one big problem I had: networking would stop working when I switched between work and home. Probably because of a different wifi. Pretty irritating, as I'd have to do a full vagrant halt and vagrant up dance. In the end, the solution was pretty obvious and simple. I didn't think of it myself though :-) The solution was on stackoverflow. Inside the VM, execute: sudo /etc/init.d/networking restart Hurray! (I've of course added it as a shell script to my personal tool/scripts/whatever collection.) -
Another scoop of Django testing
Two scoops of Django is a good book, and I recommend it to anyone who's working with Django. So when I finally got around to using travis-ci I turned to the packaging and testing chapters, but couldn't find anything that would really help me. Travis is a continuous integration service and is free for open source projects. Travis itself is also open source, so you can run your own servers in-house if necessary. Why would you want to use it? It allows you to test your applications against different OS configurations, so you can make sure your code will work on other setups, and not only on your own developement box. Even if you already test on two or three different systems, Travis will probably be an improvement. Travis-ci supports many languages other than Python, a variety of databases and even xvfb for GUI tools, which is handy for in-browser testing. Self-contained tests I always thought a package should have self-contained tests, so that you can run them without adding the app to a local project. The book focuses on doing project-wide testing. I used to use an approach of including a minimal test project in the package's source tree … -
Another scoop of Django testing
Two scoops of Django is a good book, and I recommend it to anyone who's working with Django. So when I finally got around to using travis-ci I turned to the packaging and testing chapters, but couldn't find anything that would really help me. Travis is a continuous integration service and is free for open source projects. Travis itself is also open source, so you can run your own servers in-house if necessary. Why would you want to use it? It allows you to test your applications against different OS configurations, so you can make sure your code will work on other setups, and not only on your own developement box. Even if you already test on two or three different systems, Travis will probably be an improvement. Travis-ci supports many languages other than Python, a variety of databases and even xvfb for GUI tools, which is handy for in-browser testing. Self-contained tests I always thought a package should have self-contained tests, so that you can run them without adding the app to a local project. The book focuses on doing project-wide testing. I used to use an approach of including a minimal test project in the package's source tree …