Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
django-fancy-cache with or without stats
If you use django-fancy-cache you can either run with stats or without. With stats, you can get a number of how many times a cache key "hits" and how many times it "misses". Keeping stats incurs a small performance slowdown. But how much? I created a simple page that either keeps stats or ignores it. I ran the benchmark over Nginx and Gunicorn with 4 workers. The cache server is a memcached running on the same host (my OSX 10.7 laptop). With stats: Average: 768.6 requests/second Median: 773.5 requests/second Standard deviation: 14.0 Without stats: Average: 808.4 requests/second Median: 816.4 requests/second Standard deviation: 30.0 That means, roughly that running with stats incurs a 6% slower performance. The stats is completely useless to your users. The stats tool is purely for your own curiousity and something you can switch on and off easily. Note: This benchmark assumes that the memcached server is running on the same host as the Nginx and the Gunicorn server. If there was more network in between, obviously all the .incr() commands would cause more performance slowdown. -
Django Extensions 1.1.1
Another bugfix release of Django-Extensions hits the deck. ChangeLog: FIX: pipchecker, fix typos FIX: pipchecker, improve message when installed version is newer then on pypi FIX: pipchecker, use urllib2 instead of requests FIX: sqldiff, fix for bigserial support -
ArangoDB Driver for Python: added support of Python 3.3 and ArangoDB 1.2
At least added support of Python 3.3 to the ArangoDB Python driver v 0.1.6 (github). Move forward with pip install arango. By default in Python 3.3 pycurl client will not work, so it's better to specify client by hands using: Also, added support of ArangoDB 1.2. -
PyCon Tutorial: Wiring Up Django Packages
You just finished the Django tutorial. What now? You learn how to Wire Up Django Packages! This is a 3+ hour PyCon tutorial on March 14th at 1:20pm, in Santa Clara California at PyCon US. In alphabetical order, the instructors: Audrey Roy Daniel Greenfeld (myself) Kenneth Love Tutorial Description Django is part of an ecosphere of over 20,000 packages, which can be leveraged to great effect. This tutorial will teach the evaluation, use, and extension of third party Python and Django applications in your projects. This tutorial will be a lecture with a lot of detailed and annotated code examples. This tutorial does much more than instruct on how to wire in third party packages, it also instructs on Django/Python best practices such as PEP-8, loose coupling, good database design, clarity of concept, and workable patterns. Material covered: Evaluating packages using Django Packages, PyPI, Read the Docs, and other sources. Must-include packages for every project Class-based Views Forms Models Caching Comments Templates Admin Format This will be a lecture with detailed and annotated code examples. Attendees will have a chance per section to ask questions and submit alternative packages of their own. Prerequisites Practical or professional experience with Django is … -
PyCon Tutorial: Wiring Up Django Packages
You just finished the Django tutorial. What now? You learn how to Wire Up Django Packages! This is a 3+ hour PyCon tutorial on March 14th at 1:20pm, in Santa Clara California at PyCon US. In alphabetical order, the instructors: Audrey Roy Daniel Greenfeld (myself) Kenneth Love Tutorial Description Django is part of an ecosphere of over 20,000 packages, which can be leveraged to great effect. This tutorial will teach the evaluation, use, and extension of third party Python and Django applications in your projects. This tutorial will be a lecture with a lot of detailed and annotated code examples. This tutorial does much more than instruct on how to wire in third party packages, it also instructs on Django/Python best practices such as PEP-8, loose coupling, good database design, clarity of concept, and workable patterns. Material covered: Evaluating packages using Django Packages, PyPI, Read the Docs, and other sources. Must-include packages for every project Class-based Views Forms Models Caching Comments Templates Admin Format This will be a lecture with detailed and annotated code examples. Attendees will have a chance per section to ask questions and submit alternative packages of their own. Prerequisites Practical or professional experience with Django is … -
Caktus is hiring a Web Project Manager
Caktus is currently hiring for a full time Web Project Manager to be a part of our awesome team. We’re a diverse team of smart, sharp developers and designers with a passion for creating customizable, content rich sites and web applications using Django. As one of the project managers at Caktus, you’ll have the opportunity to develop your professional skills and also get the chance to work with some very capable and nice people. We are looking for someone who is meticulous when it comes to detail, is able to see the overarching goals of projects and has a special place in their heart for spreadsheets. Also it would not hurt if you had knowledge about Django and agile web development. Your job will consist of assisting with product deployments, managing client communications and assisting with creating estimates for incoming projects. If you think you might be a great fit or know someone who might be, check out the full job posting here . -
Taking Some Pain out of Python Logging
Even the best of us hate logging in Python sometimes. And while a lot of its problems are actually just bad docs and terrible defaults in the past, there is some pain that can be avoided. One of the big problems with logging in general is that every class and function reek of NIH in the name of cross-platform. And to make it even more fun, there are several ways to do it: standard library, Twisted, Logbook… For example to get useful log rotation by day (whoever came up with rotating by size may be a good idea‽), you’d go for TimedRotatingFileHandler in stdlib, but in Twisted everything works slightly differently. All of this isn’t just annoying, it’s also unnecessary. Your UNIX-like operating system – which you presumably use to deploy your applications – offers formidable solutions to both logging and rotating. It’s out there for you to use. Since the 1980s. Nowadays when I deploy web applications I use StreamHandler as logger which sends all logs go to stderr. For paster (Pylons/Pyramid) it looks like this: [handler_stderr] class = StreamHandler args = (sys.stderr,) level = INFO formatter = your_formatter For Django, you go with: 'handlers': { 'stderr': { 'level': … -
Testing and tracking down Warnings in Django
Warnings are often suppressed through many layers of control mechanisms in Python and Django. However, you should really be aware of these and clean them up once in a while! In other cases, the Warnings reflect an inconsistent state, such as if you are mixing naive and timezone-aware variables. It can be a real pain to track down RuntimeWarning because it doesn’t leave a nice stack trace. The scenario could be that you have assigned a naive DateTime to a field, and the db layer is complaining at runtime. However, you can run python in a mode where Warning-types raise exceptions with full stack traces. Use the following syntax: python -W error:"":RuntimeWarning:django.db.models.fields:0 manage.py runserver ‘error’ means that python should raise an exception – this is what we want! ‘RuntimeWarning’ means to trigger when such is raised – you can also simply put ‘Warning’ to trigger for all Warning types. ‘django.db.models.fields’ means activate for this module (you need the full path). Notice that simply putting ‘django’ does *not* activate for all of django, you need to put the specific module or simply ‘”"‘ to enable for all of Python (which might render some interesting Warning goodies that you have never seen!). … -
This site is now 100% inline CSS and no bytes are wasted
This personal blog site of mine uses django-fancy-cache and mincss. What that means is that I can cache the whole output of every blog post for weeks and when I do that I can first preprocess the HTML and convert every external CSS into one inline STYLE block which will only reference selectors that are actually used. To see it in action, right-click and select "View Page Source". You'll see something like this: /* Stats about using github.com/peterbe/mincss ------------------------------------------- Requests: 1 (now: 0) Before: 81Kb After: 11Kb After (minified): 11Kb Saving: 70Kb */ section{display:block}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-tex... The reason the saving is so huge, in my case, is because I'm using Twitter Bootstrap CSS framework which is awesome but as any framework, it will inevitably contain a bunch of stuff that I don't use. Some stuff I don't use on any page at all. Some stuff is used only on some pages and some other stuff is used only on some other pages. What I gain by this, is faster page loads. What the browser does is that it, gets a URL, downloads all HTML, opens the HTML to look for referenced CSS (using the link tag) and downloads that too. Once all … -
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 > …