Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Useful Packages for Django projects (part 1)
This is the first of a series of posts about which libraries and tools we use for our Django development. Almost every Nomadblue project will have the following packages in their requirements.txt pip file. Probably most of the readers won't find much news here; however, eventually someone can realize he was missing something that could be leveraging their productivity or making life easier. Pillow As stated by the library documentation, Pillow is the "friendly" PIL fork by Alex Clark and Contributors. With Pillow you can stay cool as it installs smoothly using pip, and also you can sleep at night because somebody is maintaining the library in a healthy state through continuous integration, regular releases, bug fixing and development on github, and active participation on the Imaging-SIG. South When we started with Django (more than 5 years so far) there were a bunch of migration libraries out there, with different approaches. Andrew Godwin became a frequent flyer on the Django community, eventually winning the pulse and gathering the Djangonauts until South became a "must" or "de-facto" library to manage your database schema and data transitions. Worth mentioning that Andrew recently applied at kickstarter for a call to develop "a new, … -
Google Analytics tracking code into Django projects, the easy way
Creating a pluggable Django app to just embed the GA code seemed overkill to me, so I created this post as a quick reference for next Django web projects. The idea is creating a system that will add the tracking code under the following conditions: We have provided the ID and domain of our GA configuration. We are not running in settings.DEBUG mode. Settings variables The following settings must be defined on your settings.py. GOOGLE_ANALYTICS_PROPERTY_ID A string containing your ID on GA (e.g. UA-14845987-3). Get it from your configuration page: GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-14845987-3' GOOGLE_ANALYTICS_DOMAIN This means the root domain you registered in Google Analytics. Even if you are configuring a subdomain (e.g. www.mydoamin.com or foo.mydomain.com) you must use the root domain. For instance, mydomain.com: GOOGLE_ANALYTICS_DOMAIN = 'mydomain.com' Context Processor Add this function to your context processors file: from django.conf import settings def google_analytics(request): """ Use the variables returned in this function to render your Google Analytics tracking code template. """ ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_ID', False) ga_domain = getattr(settings, 'GOOGLE_ANALYTICS_DOMAIN', False) if not settings.DEBUG and ga_prop_id and ga_domain: return { 'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id, 'GOOGLE_ANALYTICS_DOMAIN': ga_domain, } return {} Add the context processor to your settings: TEMPLATE_CONTEXT_PROCESSORS = ( ... 'website.context_processors.google_analytics', ) Template … -
Not a Fan of Django
Hynek Schlawack presents us with some Django criticism while talking with us about static media, test speed, mezzanine theming, a pypi wrapper, logging, markdown docs, interceptors, admin styling, pycon keynotes, and test servers. -
Django on windows: how to make Django run in CherryPy as a Windows service
Recently a client asked me to investigate the possibility to have a Django application hosted in a Windows environment. I looked around a bit and there are many ways to achieve this goal. I found the “pure Python” approach described here simpler to deploy and configure, yet very powerful and production ready for my needs. I will explain how to install Python, CherryPy and Django on Windows, and how to configure them to serve a Django application from the CherryPy WSGI server, running as a Windows service. Table of Contents Install Python 2.7 Install CherryPy CherryPy server started as a Windows Service Install Django Give a powerful DB engine to your Django app: install MySQL! Make your Django project an installable python package Django running in CherryPy as a Windows service Conclusions Install Python 2.7 First of all you have to install the Python programming language support for Windows. I used Python 2.7.5 Windows Installer. Then to be able to invoke the python command from the command line – no matter what the current work directory is – add Python to system path. Go to Control panel > System > Advanced > Environment variables look for path variable, click on … -
Number Theoretic Algorithms – Factorization
In the following series of posts, I will write about some of the number theoretic algorithms that one encounters in most of competitive programming. These are fundamental algorithms which most computer scientist should know. In this post I will post an algorithm and a corresponding JAVA code to perform prime factorization of a give number. The algorithm to perform prime factorization is a very trivial algorithm and mostly encountered by everyone atleast once in their high school. - Iterate for i from 1 to sqrt(n) - While i|n, divide n by i. Report i as a prime factor of n - After the iteration of i from 1 to sqrt(n), if n is a number greater than 1, report that also as a prime factor The key observation is that, this algorithm runs in O(square root (n) ). We are able to iterate only upto sqrt(n) since, we can claim one of the following: 1) n is a prime number or 2) If n has a prime factor p greater than sqrt(n), then there exists a corresponding prime factor p’ lesser than or equal to sqrt(n), such that p*p’ = n If (1) doesn’t hold, it implies that n is … -
Tagging with django-taggit
In this video you will learn an easy way to add tags to your models, and on your site. Tags can be hard if you try to implement them yourself, so don't try and just use this library from the start.Watch Now... -
Ecoscope
Brett Cannon joins us to talk about PyTenessee, performance, cookiecutter, flask foundation, scaling, raw sql migrations, code review, waffling, sockets, pixel tracking, and even cooking. -
Skipping Test DB Creation
We are always looking for ways to make our tests run faster. That means writing tests which don't preform I/O (DB reads/writes, disk reads/writes) when possible. Django has a collection of TestCase subclasses for different use cases. The common TestCase handles the fixture loading and the creation the of TestClient. It uses the database transactions to ensure that the database state is reset for every test. That is it wraps each test in a transaction and rolls it back once the test is over. Any transaction management inside the test becomes a no-op. Since TestCase` overrides the transaction facilities, if you need to test the transactional behavior of a piece of code you can instead use TransactionTestCase. TransactionTestCase resets the database after the test runs by truncating all tables which is much slower than rolling back the transaction particularly if you have a large number of tables. There is also SimpleTestCase which is the base class for the previous to classes. It has some additional assertions for testing HTML and overriding Django settings but doesn't manage the database state. If you are testing something that doesn't need to interact with the database such as form field/widget output, utility code or … -
Skipping Test DB Creation
We are always looking for ways to make our tests run faster. That means writing tests which don't preform I/O (DB reads/writes, disk reads/writes) when possible. Django has a collection of TestCase subclasses for different use cases. The common TestCase handles the fixture loading and the creation the of TestClient. It uses the database transactions to ensure that the database state is reset for every test. That is it wraps each test in a transaction and rolls it back once the test is over. Any transaction management inside the test becomes a no-op. Since [TestCase]{.title-ref}[ overrides the transaction facilities, if you need to test the transactional behavior of a piece of code you can instead use ]{.title-ref}[TransactionTestCase]{.title-ref}[. ]{.title-ref}[TransactionTestCase]{.title-ref}` resets the database after the test runs by truncating all tables which is much slower than rolling back the transaction particularly if you have a large number of tables. -
Guilt Trip
Eric Holscher jumps in to talk about blogging, deployment, the latest community news and project releases, teaching kids to code, and his experiment to support his community contributions through gittip. -
Django Projects
Over the past 6 years, I've built a lot of things with Django. It has treated me very well, and I have very much enjoyed seeing it progress. I got into Django when I helped the company I was working for transition away from a homegrown PHP framework toward something more reliable and flexible. It was very exciting to learn more about Django at a time when the ecosystem was very young. When I started with Django, there weren't a lot of pluggable apps to fill the void for things like blogs, event calendars, and other useful utilities for the kinds of sites I was building. That has changed quite a bit since then. The ecosystem has evolved and progressed like mad, and it's wonderful. We have so many choices for simple things to very complex things. It's amazing! Unfortunately, during this whole time period, my development efforts have shifted from creating my own open source projects to share with the world toward more proprietary solutions for my employers. If it's not obvious to you from my blog activity in recent years, I've become very busy with family life and work. I have very little time to give my open … -
django-waffle
Learn how to use this popular feature flipper for helping you to develop and test new features live instead of only in development.Watch Now... -
Brilliant or Insane?
This week, Kenneth and Brandon are joined by Bryan Veloso. We talk about the several official Django announcements last week, when maintainability should be sacrificed for performance, algorithmic wedding seating, promises (or futures) in concurrent programming, the Django Pony, and more! -
Personal lessons from XOXO
Three things I want to remember from XOXO, written in haste as the conference wraps up: Optimism XOXO is so un-snarky, so radically honest and sincere, that it almost feels like another world. XOXO is an amazing departure from that. The sincerity and friendliness is so total, so comfortable. A number of speakers shared intensely personal moments: Marco called his talk a “group therapy session” and discussed his fear and insecurity; Cabel shared a story of depression that was heartfelt and resonant. -
How to Create a File Upload Widget
Ajaxified file uploads are becoming de facto standard on the web. People want to see what they chose right after selecting a file instead of during submit of the form. Also if a form has validation errors, nobody wants to select the files again; the selection made should be still available in the form. Therefore, we need a solution that works by Ajax. Luckily there is a Django app that can help. It's called django-ajax-uploader. Ajax uploader allows to create asynchronous single and multiple file uploads. All uploads are done into the uploads directory. In addition to the default functionality we need a possibility to show the preview of the temporary uploaded file, translate all messages and buttons, delete a file, move a file to a specific directory. I created a demo project which implements all that. If you have a ModelForm with a FileField or ImageField, you need to not show this field in the form, but instead to add a hidden field for uploaded file path. When you choose a file, it will be uploaded to a temporary uploads directory and its path will be set in the hidden field. Also you need a hidden BooleanField for the … -
First thoughts about Django-CMS
I just set up a site using Django-CMS over at Pomme d'Api Preschool. Overall, I am pretty impressed. I really like the Django admin interface enhancements as well as the site overlay editing feature. One of the best things it he use of django-filer, a file management tool to manage all the uploads to the site. It's awesome and it makes me want to throw out this home page completely and switch over to Django-CMS. Image handling in Drupal has always sucked and still does. The fact that there was no official media/image handling in Drupal 6 sucks, and it's made worse by the fact that there is no real upgrade path to Drupal 7 for media/images, especially if you're like me and you used the "Image" and "image-assist" modules, two of the most popular modules dealing with images. Django-CMS is pretty powerful and so far it has allowed me to do pretty much anything I have wanted to do. -
Central logging in Django with Graylog2 and graypy
.. |--| unicode:: U+2013 .. en dash .. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace :trim: Django's `logging configuration `_ facilities, which arrived in version 1.3, have greatly eased (and standardized) the process of configuring logging for Django projects. When building complex and interactive web applications at Caktus, we've found that detailed (and properly configured!) logs are key to successful and efficient debugging. Another step in that process |---| which can be particularly useful in environments where you have multiple web servers |---| is setting up a centralized logging server to receive all your logs and make them available through an easily accessible web interface. There are a number useful tools to do this, but one we've found that works quite well is `Graylog2 `_. Installing and configuring Graylog2 is outside the scope of this post, but there are plenty of tutorials on how to do so accessible through your search engine of choice. Once you have it setup, getting logs flowing to Graylog2 from Django is relatively straightforward. First, grab a copy of the ``graypy`` package from PyPI and add it to your requirements file:: pip install -U graypy Next, add the following configuration inside the ``LOGGING['handlers']`` … -
Central logging in Django with Graylog2 and graypy
Django's logging configuration facilities, which arrived in version 1.3, have greatly eased (and standardized) the process of configuring logging for Django projects. When building complex and interactive web applications at Caktus, we've found that detailed (and properly configured!) logs are key to successful and efficient debugging. Another step in that process — which can be particularly useful in environments where you have multiple web servers — is setting up a centralized logging server to receive all your logs and make them available through an easily accessible web interface. There are a number useful tools to do this, but one we've found that works quite well is Graylog2. Installing and configuring Graylog2 is outside the scope of this post, but there are plenty of tutorials on how to do so accessible through your search engine of choice. -
Django Round-Up #10
This week we're joined by Portia Burton! We discuss Portland, Mozilla Persona, making a game board, migrations and South's frozen ORM, Bee Ware and GUI tools vs. the command line, clever comprehensions, and a whole lot more. -
crispy-forms
Learn how to get started using the popular crispy forms django application to streamline rendering your templates by doing your layout in python.Watch Now... -
Django Round-Up #9
Miguel Grinberg joins us for a very Python and Flask centered episode where we discuss color themes, video processing, web scraping, class-based views, and learning Flask. -
Wedding hacks - seating planner using simulated annealing
This is the third in a seris of posts in which my upcoming wedding has exercised my programming skills. The problem There are a lot of ways to seat approx 130 guests in tables of 10. (Digression: how many ways? There n! ways to order a list of n people. We then group that list of n people into j groups (tables) of size k each (assuming an exact division is possible for simplicity). In each group, there are k! different ways to order the people, but all these are considered equivalent for our purposes. So we divide by k!, and do it j times, once for each table. We could then shuffle all the groups, and all the results of such shuffling are also considered equivalent. So we divide by j! to count for these permutations. So, I make it: n!/(j*k!*j!) Or, in my case: 22, 014, 379, 788, 144, 009, 262, 986, 489, 297, 967, 619, 407, 616, 773, 070, 962, 391, 042, 003, 562, 758, 124, 860, 965, 657, 753, 242, 386, 208, 110, 081, 303, 218, 233, 306, 048, 808, 531, 260, 440, 119, 599, 226, 289, 816, 251, 326, 745, 993, 359, 038, 728, 297, … -
Wedding hacks - John Lewis gift list hyperlink
I'm getting married in 3 weeks time - yay! But this post isn't about that — it's a quick programming-and-wedding-related tip. We set up a John Lewis gift list, but we found the web site's instructions for use could be improved. The instructions to pass on to potential givers were: Go to this site Type in this gift list number That's fine for printed instructions, but if you already have a website, there is this magical thing called a hyperlink which should be able to take you straight there, without any error prone typing etc. John Lewis didn't provide any instructions for doing this, and as the number never appears in a URL, even after this point, it isn't obvious that there is a way to do it. However, I managed to impress my fiancée with my leet hacking skills to get around this. OK, so I right clicked at an appropriate place, chose “Inspect element”, applied some knowledge of web development and made a few easy guesses. I came up with the following URL which works, and will take you straight to your gift list: https://www.johnlewisgiftlist.com/giftint/guestpassword?giftListNumber=YOURNUMBER Just replace YOURNUMBER with your actual number. That's all for now - but … -
Personafied
Reminder for people who try and think it’s a bug: Persona, on this site, is for me to be able to log in and post entries. As such, you will not be able to log in to this site, since you don’t have an account and can’t create one. This isn’t a bug, it’s intended functionality — site owners can control whether accounts can be created, and by whom. So, last ... Read full entry -
Personafied
Reminder for people who try and think it’s a bug: Persona, on this site, is for me to be able to log in and post entries. As such, you will not be able to log in to this site, since you don’t have an account and can’t create one. This isn’t a bug, it’s intended functionality — site owners can control whether accounts can be created, and by whom. So, last week I mentioned in passing ... Read full entry