Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Hosting Django static images with Amazon Cloudfront (CDN) using django-static
About a month ago I add a new feature to django-static that makes it possible to define a function that all files of django-static goes through. First of all a quick recap. django-static is a Django plugin that you use from your templates to reference static media. django-static takes care of giving the file the optimum name for static serving and if applicable compresses the file by trimming all whitespace and what not. For more info, see The awesomest way possible to serve your static stuff in Django with Nginx The new, popular, kid on the block for CDN (Content Delivery Network) is Amazon Cloudfront. It's a service sitting on top of the already proven Amazon S3 service which is a cloud file storage solution. What a CDN does is that it registers a domain for your resources such that with some DNS tricks, users of this resource URL download it from the geographically nearest server. So if you live in Sweden you might download myholiday.jpg from a server in Frankfurk and if you live in North Carolina, USA you might download the very same picture from Virgina, USA. That assures the that the distance to the resource is minimized. … -
Hosting Django static images with Amazon Cloudfront (CDN) using django-static
About a month ago I add a new feature to django-static that makes it possible to define a function that all files of django-static goes through. First of all a quick recap. django-static is a Django plugin that you use from your templates to reference static media. django-static takes care of giving the file the optimum name for static serving and if applicable compresses the file by trimming all whitespace and what not. For more info, see The awesomest way possible to serve your static stuff in Django with Nginx The new, popular, kid on the block for CDN (Content Delivery Network) is Amazon Cloudfront. It's a service sitting on top of the already proven Amazon S3 service which is a cloud file storage solution. What a CDN does is that it registers a domain for your resources such that with some DNS tricks, users of this resource URL download it from the geographically nearest server. So if you live in Sweden you might download myholiday.jpg from a server in Frankfurk and if you live in North Carolina, USA you might download the very same picture from Virgina, USA. That assures the that the distance to the resource is minimized. … -
Feature Switches at Disqus
Wrote up a post on how we use feature switches at Disqus within Django templates and views. (In the future we'll be posting all of our tech over on the Dev section of the Disqus blog) -
Hosting Django static images with Amazon Cloudfront (CDN) using django-static
About a month ago I add a new feature to django-static that makes it possible to define a function that all files of django-static goes through. First of all a quick recap. django-static is a Django plugin that you use from your templates to reference static media. django-static takes care of giving the file the optimum name for static serving and if applicable compresses the file by trimming all whitespace and what not. For more info, see The awesomest way possible to serve your static stuff in Django with Nginx The new, popular, kid on the block for CDN (Content Delivery Network) is Amazon Cloudfront. It's a service sitting on top of the already proven Amazon S3 service which is a cloud file storage solution. What a CDN does is that it registers a domain for your resources such that with some DNS tricks, users of this resource URL download it from the geographically nearest server. So if you live in Sweden you might download myholiday.jpg from a server in Frankfurk and if you live in North Carolina, USA you might download the very same picture from Virgina, USA. That assures the that the distance to the resource is minimized. … -
Hosting Django static images with Amazon Cloudfront (CDN) using django-static
About a month ago I add a new feature to django-static that makes it possible to define a function that all files of django-static goes through. First of all a quick recap. django-static is a Django plugin that you use from your templates to reference static media. django-static takes care of giving the file the optimum name for static serving and if applicable compresses the file by trimming all whitespace and what not. For more info, see The awesomest way possible to serve your static stuff in Django with Nginx The new, popular, kid on the block for CDN (Content Delivery Network) is Amazon Cloudfront. It's a service sitting on top of the already proven Amazon S3 service which is a cloud file storage solution. What a CDN does is that it registers a domain for your resources such that with some DNS tricks, users of this resource URL download it from the geographically nearest server. So if you live in Sweden you might download myholiday.jpg from a server in Frankfurk and if you live in North Carolina, USA you might download the very same picture from Virgina, USA. That assures the that the distance to the resource is minimized. … -
Formularios con Django sin SPAM
¿Quieres luchar contra el SPAM en tus formularios sin tener que modificarlos? Una forma sencilla de evitar gran parte del SPAM automático son los snippets AntiSpamForm y AntiSpamModelForm. Están basados en los formularios anti-spam que utiliza la aplicación django.contrib.comments... -
Class based views in Django
Abstract Never been frustrated doing functional programming in your django views ? This little module is intended to help you use objects for your views : Replace urls parameters and template context by class attributes. Use inheritance to group common task, do specializations, common decorators... Define template tags in your objects, call instance methods. Define your re-usable library. This code is now quite complete and we use it in production environment. Hello World comparison Consider this example (classic way): urls.py from django.conf.urls.defaults import * from views import hello urlpatterns = patterns( '', (r'^hello/(?P<times>\d+)/$', hello), ) views.py from django.shortcuts import render_to_response from django.template import RequestContext def hello(request, times=10): name = request.user and request.user.username or 'Pony' times = range(int(times)) return render_to_response('hello.html', { 'times' : times, 'name' : name }, context_instance=RequestContext(request)) hello.html {% for i in times %} Hello {{ name }} {% endfor %} Now with ViewsObject: urls.py from django.conf.urls.defaults import * from django_pimentech.viewsobjects import ObjectCaller from views import Hello urlpatterns = patterns( '', (r'^hello/(?P<times>\d+)/$', ObjectCaller(Hello)), ) views.py from django_pimentech.viewsobjects import BaseView class Hello(BaseView): template = 'hello.html' name = None times = 10 def fill_context(self): self.times = range(int(self.times)) self.name = self.request.user and self.request.user.username or 'Pony' Besides the object syntax, the main idea … -
Django navigation bar (active link highlighting)
Every web application needs a navigation bar. Common practice is to indicate to the user where he or she is, and is usually implemented by using a visual aid such as a bold type-face, different color or an icon. I wanted an elegant, generic, extendable solution to "highlight" a link on the navigation bar without hardcoding URLs, using ifequals, or using template block inheritance by specifying a navbar block on each and every template (you'd be surprised, but the above mentioned are recommend often). The solution I came up with is quite simple. No need to hardcode URLs (using urlconf names). Navbar is only specified in the base template (actually a separate template loaded by the base template). By using a simple template tag and the request context processor, "active" will be returned if the "link" should be active. Supports multiple URLs for each link. CSS is used to highlight the active link. You can see the above in action on the TurnKey Hub. On to the code First up, we need to enable the request context processor. settings.py TEMPLATE_CONTEXT_PROCESSORS = ( ... 'django.core.context_processors.request', ) Next, create the template tag navactive. Note: the navigation sitemap I'm using is flat, but you can … -
Django navigation bar (active link highlighting)
Every web application needs a navigation bar. Common practice is to indicate to the user where he or she is, and is usually implemented by using a visual aid such as a bold type-face, different color or an icon. I wanted an elegant, generic, extendable solution to "highlight" a link on the navigation bar without hardcoding URLs, using ifequals, or using template block inheritance by specifying a navbar block on each and every template (you'd be surprised, but the above mentioned are recommend often). The solution I came up with is quite simple. No need to hardcode URLs (using urlconf names). Navbar is only specified in the base template (actually a separate template loaded by the base template). By using a simple template tag and the request context processor, "active" will be returned if the "link" should be active. Supports multiple URLs for each link. CSS is used to highlight the active link. You can see the above in action on the TurnKey Hub. On to the code First up, we need to enable the request context processor. settings.py TEMPLATE_CONTEXT_PROCESSORS = ( ... 'django.core.context_processors.request', ) Next, create the template tag navactive. Note: the navigation sitemap I'm using is flat, but you can … -
Django navigation bar (active link highlighting)
Every web application needs a navigation bar. Common practice is to indicate to the user where he or she is, and is usually implemented by using a visual aid such as a bold type-face, different color or an icon. I wanted an elegant, generic, extendable solution to "highlight" a link on the navigation bar without hardcoding URLs, using ifequals, or using template block inheritance by specifying a navbar block on each and every template (you'd be surprised, but the above mentioned are recommend often). The solution I came up with is quite simple. No need to hardcode URLs (using urlconf names). Navbar is only specified in the base template (actually a separate template loaded by the base template). By using a simple template tag and the request context processor, "active" will be returned if the "link" should be active. Supports multiple URLs for each link. CSS is used to highlight the active link. You can see the above in action on the TurnKey Hub. On to the code First up, we need to enable the request context processor. settings.py TEMPLATE_CONTEXT_PROCESSORS = ( ... 'django.core.context_processors.request', ) Next, create the template tag navactive. Note: the navigation sitemap I'm using is flat, but you can … -
Django 1.1 Testing and Debugging
I borrowed a copy of Django 1.1 Testing and Debugging from a friend today. Spent the bus ride home from the office flipping through the pages, and I’ve got to say – it’s a pretty darned good book! If you’re … Continue reading → -
Investing in Yourself - A review of Django 1.1 Testing and Debugging by Karen M. Tracey
Packt Publishing recently asked me to read and review Django 1.1 Testing and Debugging and I have to admit I really enjoyed reading this book. Often I find myself debating whether or not to purchase a new development book. I'm usually thinking "If I spend $XX.XX on this book, will I really learn anything worth that much?". Especially considering most answers are a few Google searches away. I can happily attest this book is definitely worth the cost. The book starts off with the usual introduction to testing, discussing both Doctests and Unittest, which is obviously required for a book on this subject. However, this book differs greatly from many in that it walks you through testing and debugging your application as you would when building a real application. Many tech books strive to be a great tutorial, but often fall short of the mark and end up just being some verbiage around a rehashing of the available documentation. They end up being more reference than tutorial. Django 1.1 Testing and Debugging however does a great job of walking you through real world scenarios. For example, it covers topics (and in the proper order in my opinion) like: Test coverage … -
Adding Geolocation Support to GeoDjango Admin
GeoDjango is awesome. It’s one of those frameworks that does an amazing amount of heavy lifting for you behind the scenes so you can just focus on your implementation. There was one thing that has been bugging me about it since day one though: the map picker tool used in the administration area doesn’t focus on your current location automatically. It simply gets initialized somewhere around Cameroon, and you have to pan and zoom your way around the world every time you want to add a single point, or polygon, most likely near where you are. Adding geolocation support to this map has been surprisingly easy. Google Chrome, Firefox, and now Safari 5 all support geolocation, through W3C Geolocation Standard. Google Maps API documentation includes a very handy JavaScript snippet that you can use to activate this feature, and it even has fallback support for browsers that have Google Gears installed, which has its own geolocation support. Without further ado, let’s get into the code. First, I switched the GeoDjango admin to use a Google Maps layer instead of the default Open Street Maps one. It’s simply better in terms of visuals and readability, and people are much more used … -
Ubuntu 10.04 (Desktop)
I’ve been using Ubuntu as my distribution of choice for VM’s and server instances, and on a lark I took a swag at installing Ubuntu desktop onto a VM yesterday. I’ve got to say, it’s a pretty usable setup. I … Continue reading → -
Django caché invalidation
Un dels problemes més importants del desenvolupament d'aplicacions web que necessiten suportar una gran quantitat de visités és el de decidir com es farà l'arquitectura de caché i quan i com s'invalida el contingut de la mateixa. Al respecte he trobat dues presentacions realment excel·lents de la Djangocon: Scaling Django Web Applications Static Generator Les dues són molt bones, però especialment us recoman la segona si voleu passar una estona divertida a més d'aprendre com funciona el tema de les cachés. Jared Kuolt broda una presentació plena d'ocurrències, dobles sentits i acudits freaks al mateix temps que aconsegueix introduir-nos en la problemàtica de les cachés. La primera presentació té moltíssima informació, Michel Malone de Pownce explica els problemes que s'han trobat a Pownce i com els han anat solucionant a Django. El problema fonamental de les cachés a Django és el tema de la invalidació. Django oculta bastant el nom de les claus que genera i sense aquestes claus un no pot anar a Memecached per invalidar-les. La sol·lució passa invariablement per generar les nostres pròpies claus de manera repetible i fer un us dels signals de Django per a realitzar la invalidació de les cachés. Això vol dir ser … -
Using virtualenv, pip and django-site-gen to quickly start new Django projects
Last week, after several false starts, I moved all the sites I maintain into virtualenvs, with their own pip requirements files. My reasons for doing so are pretty simple: Experimenting with new/different versions of software is a pain in the ass without isolation A pip requirements file for each site is a very nice thing to behold I symlink 3rd party apps into a custom directory on my PYTHONPATH and it was getting huge Profit There are quite a few great tutorials out there for getting started with these tools. I will only discuss how I got over some of the hurdles involved in using these tools, as well as a tool for automating the creation of "skeleton" django sites. -
What’s the Deal With: Django Template Indentation
I like my source code to look good (if at all possible). Django definitely helps with this but you are essentially in a 0 sum game. You make your template code look good or your output HTML source look good, not both it seems. OK, so in the docs you will first of all come [...] -
update script for unittest2 integration
Django is moving to use unittest2 as part of the default test suite. Unfortunately, it needs to be bundled, which means that it will live in django.utils.unittest rather than in the pythonpath where it expects to be. This means that we need to patch the import statements. I’ve written a little script to download the [...] -
What to do with Locidesktop?
So what to do with locidesktop.com? It's a desktop-like website bookmarking tool – if you haven't seen it, take a quick look at this example desktop. I built Loci Desktop a few months ago and promoted it on a few geek sites. It's been running ever since, with no maintenance from myself, happily serving up start pages to a small number of regular users. There was a buzz when I promoted it, people were largely impressed, some were indifferent, but few ended up using it regularly. So now I'm left with a quandary. I could try and promote it. But to what end? It's not like I need a certain number of visitors to cover the hosting. I'm using the same VPS as I am for my blog, and I designed Locidesktop to be ultra-low bandwidth anyway – so it effectively costs me nothing to run. One option would be to sell the entire site outright, as the domain and technology rights. But there is currently no way of monetizing it and I doubt anyone would be interested as a commercial venture. I could try and license it as a b2b service. A few people have commented that it would … -
What to do with Locidesktop?
So what to do with locidesktop.com? It's a desktop-like website bookmarking tool – if you haven't seen it, take a quick look at this example desktop. I built Loci Desktop a few months ago and promoted it on a few geek sites. It's been running ever since, with no maintenance from myself, happily serving up start pages to a small number of regular users. There was a buzz when I promoted it, people were largely impressed, some were indifferent, but few ended up using it regularly. So now I'm left with a quandary. I could try and promote it. But to what end? It's not like I need a certain number of visitors to cover the hosting. I'm using the same VPS as I am for my blog, and I designed Locidesktop to be ultra-low bandwidth anyway – so it effectively costs me nothing to run. One option would be to sell the entire site outright, as the domain and technology rights. But there is currently no way of monetizing it and I doubt anyone would be interested as a commercial venture. I could try and license it as a b2b service. A few people have commented that it would … -
What to do with Locidesktop?
So what to do with locidesktop.com? It's a desktop-like website bookmarking tool – if you haven't seen it, take a quick look at this example desktop. I built Loci Desktop a few months ago and promoted it on a few geek sites. It's been running ever since, with no maintenance from myself, happily serving up start pages to a small number of regular users. There was a buzz when I promoted it, people were largely impressed, some were indifferent, but few ended up using it regularly. So now I'm left with a quandary. I could try and promote it. But to what end? It's not like I need a certain number of visitors to cover the hosting. I'm using the same VPS as I am for my blog, and I designed Locidesktop to be ultra-low bandwidth anyway – so it effectively costs me nothing to run. One option would be to sell the entire site outright, as the domain and technology rights. But there is currently no way of monetizing it and I doubt anyone would be interested as a commercial venture. I could try and license it as a b2b service. A few people have commented that it would … -
Continuous Integration Testing
At work we recently set up Buildbot to replace an in-house continuous integration tool that never really took off. I’ve used Buildbot before, in a hobby capacity, but using it my day job has really brought home to me how important not only testing is, but testing continuously. Buildbot is pretty simple to explain. Every [...] -
RSS feeds with Django syndication feed framework
Implemented the working of feeds with this site. Now, you can subscribe to live RSS feed from this site, which have been implemented using the Django Syndication Feed Framework 1.2 and later. Currently it supports RSS feeds following the specifications stated at RSS v2. Atom feeds will be added later on in future. To Subscribe to live feeds, Click Here. -
RSS feeds with Django syndication feed framework
Implemented the working of feeds with this site. Now, you can subscribe to live RSS feed from this site, which have been implemented using the Django Syndication Feed Framework 1.2 and later. Currently it supports RSS feeds following the specifications stated at RSS v2. Atom feeds will be added later on in future. To Subscribe to live feeds, Click Here. -
Uploads to Blobstore and GridFS with Django
We've finished our App Engine Blobstore and MongoDB GridFS storage backends for Django. With these backends you can directly use FileField and ModelForm to easily handle file uploads in a portable way. You can see a demo in action on App Engine at http://django-filetransfers.appspot.com/ and also have a look at the demo's source code. The App Engine Blobstore backend is already integrated and pre-configured in djangoappengine. The GridFS backend is now part of django-storages. However, that's only the first half of the solution. In addition to the storage backends we've also created a reusable Django app called django-filetransfers which provides a simple API for upload and download handling in your views. This API is an abstraction over the little details in the different file hosting services. For example, in a traditional Apache/Lighttpd/nginx setup you might want to efficiently serve files via your web server instead of Django by using the "X-Sendfile" extension. App Engine requires that you use a modified upload URL. Asynchronous uploads to Amazon S3 (i.e., the browser sends the file directly to S3 instead of piping it through your Django instance) require that you generate a custom upload URL and use additional POST data to authorize the …