Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Almost premature optimization
In airmozilla the tests almost all derive from one base class whose tearDown deletes the automatically generated settings.MEDIA_ROOT directory and everything in it. Then there's some code that makes sure a certain thing from the fixtures has a picture uploaded to it. That means it has do that shutil.rmtree(directory) and that shutil.copy(src, dst) on almost every single test. Some might also not need or depend on it but it's conveninent to put it here. Anyway, I thought this is all a bit excessive and I could probably optimize that by defining a custom test runner that is first responsible for creating a clean settings.MEDIA_ROOT with the necessary file in it and secondly, when the test suite ends, it deletes the directory. But before I write that, let's measure how many gazillion milliseconds this is chewing up. Basically, the tearDown was called 361 times and the _upload_media 281 times. In total, this adds to a whopping total of 0.21 seconds! (of the total of 69.133 seconds it takes to run the whole thing). I think I'll cancel that optimization idea. Doing some light shutil operations are dirt cheap. -
Almost premature optimization
In airmozilla the tests almost all derive from one base class whose tearDown deletes the automatically generated settings.MEDIA_ROOT directory and everything in it. Then there's some code that makes sure a certain thing from the fixtures has a picture uploaded to it. That means it has do that shutil.rmtree(directory) and that shutil.copy(src, dst) on almost every single test. Some might also not need or depend on it but it's conveninent to put it here. Anyway, I thought this is all a bit excessive and I could probably optimize that by defining a custom test runner that is first responsible for creating a clean settings.MEDIA_ROOT with the necessary file in it and secondly, when the test suite ends, it deletes the directory. But before I write that, let's measure how many gazillion milliseconds this is chewing up. Basically, the tearDown was called 361 times and the _upload_media 281 times. In total, this adds to a whopping total of 0.21 seconds! (of the total of 69.133 seconds it takes to run the whole thing). I think I'll cancel that optimization idea. Doing some light shutil operations are dirt cheap. -
Terrible choices: MySQL
I've used MySQL for a while now, and there were lots of surprising things I needed to cater for. This is from a Django and MySQL 5.5 perspective [*]. Later on you'll see the horrible things I did to work around. It was a terrible experience, as I've also used PostgreSQL ... Feel free to add your own experiences in the comments section. The defaults* MySQL supports a large part of the ANSI SQL 99 standard, however the default settings are nowhere close to that. If you used any other database then it's going to be a very perplexing experience. SQL mode* With the default settings MySQL truncates and does other unspeakable things to data for the sake of not giving errors. Where is this a correct choice, hard to say. What the defaults allow: Storing invalid dates like '0000-00-00' or '2010-01-00' [1]. Silently treating errors like: Specifying an unavailable storage engine. It will use the default engine, silently [2]. Inserting invalid data. Larger strings get truncated to the maximum length. Larger integers get truncated to the maximum. Other things get converted to NULL if the column allows that. All silently [3]. And no, ORMs won't save you from this … -
Terrible choices: MySQL
I've used MySQL for a while now, and there were lots of surprising things I needed to cater for. This is from a Django and MySQL 5.5 perspective [*]. Later on you'll see the horrible things I did to work around. It was a terrible experience, as I've also used PostgreSQL ... Feel free to add your own experiences in the comments section. The defaults * MySQL supports a large part of the ANSI SQL 99 standard, however the default settings are nowhere close to that. If you used any other database then it's going to be a very perplexing experience. SQL mode * With the default settings MySQL truncates and does other unspeakable things to data for the sake of not giving errors. Where is this a correct choice, hard to say. What the defaults allow: Storing invalid dates like '0000-00-00' or '2010-01-00' [1]. Silently treating errors like: Specifying an unavailable storage engine. It will use the default engine, silently [2]. Inserting invalid data. Larger strings get truncated to the maximum length. Larger integers get truncated to the maximum. Other things get converted to NULL if the column allows that. All silently [3]. And no, ORMs won't save you … -
Terrible choices: MySQL
I've used MySQL for a while now, and there were lots of surprising things I needed to cater for. This is from a Django and MySQL 5.5 perspective [*]. Later on you'll see the horrible things I did to work around. It was a terrible experience, as I've also used PostgreSQL ... Feel free to add your own experiences in the comments section. The defaults * MySQL supports a large part of the ANSI SQL 99 standard, however the default settings are nowhere close to that. If you used any other database then it's going to be a very perplexing experience. SQL mode * With the default settings MySQL truncates and does other unspeakable things to data for the sake of not giving errors. Where is this a correct choice, hard to say. What the defaults allow: Storing invalid dates like '0000-00-00' or '2010-01-00' [1]. Silently treating errors like: Specifying an unavailable storage engine. It will use the default engine, silently [2]. Inserting invalid data. Larger strings get truncated to the maximum length. Larger integers get truncated to the maximum. Other things get converted to NULL if the column allows that. All silently [3]. And no, ORMs won't save you … -
Custom Django Admin Actions
Doing bulk data actions in the admin is easy, if you know how to do it. In this video you will learn how to create your own custom admin actions so you can update a lot of data objects all at the same time.Watch Now... -
BangPypers Dev Sprint!
Here is the definition of sprint from Wikipedia:On 3rd Saturday of every month there will be a meetup for Python developers in Bangalore(BangPypers) to have talks and workshops. This month instead of talks/workshops, a dev sprint was held. The basic idea was to encourage Python developers to contribute to any open source projects or work on their open source projects.I was working on Nidaba, a project to extract information from StackOverflow dumps. I went to the meetup and gave a brief description about it. Several people were interested to work. I helped them a bit on getting started and the issues to solve. By the end of event, I got one pull request which fixed a typo in setup file. Few people helped in adding couple of utility functions for the project. A couple of them were interested to continue working on with it in the coming weekends. In the end PSSI sponsored T-shirt :) Here are a few snapshots of event. -
A quick introduction to Docker containers for Django web developers
Docker is a platform for running applications in isolation. Using Linux containers makes the software layer isolated from the base system. The overhead needed for hardware virtualization used by for example Virtualbox is removed. Docker can help in development and deployment of web based applications and services - let us see how and when. -
I did an Aú Batido in 2014, now what?
This is my summary of my resolutions for 2014 and an early pass at my resolutions for 2015. I'm doing this right now instead of at the end of the year because as of the afternoon of December 21, I'm going off the grid. Resolutions Accomplished in 2014 Release the second edition of Two Scoops of Django. Visited South America. Visited two new nations, Argentina and Brazil. Went back to the East Coast to visit Philadelphia and places in New Jersey. Went back to the Philippines. Took some awesome road trips around the USA. My favorite was driving up the Pacific Coast Highway. Took a fun class with Audrey. We did woodshop! Learned how to do Aú Batido! General Accomplishments Published Two Scoops of Django 1.6 with my awesome wife, Audrey Roy Greenfeld. Experienced my first major surgery. Started working at Eventbrite. Found a Inland Empire Capoeira group but still remained friends with Capoeira Batuque. Gave talks at: Wharton School of Business Web Conference PyDay Mendoza Python Brazil PyCon Argentina Experienced the unbelievably tasty asado (steak) of Argentina. Participated in organizing the first Django Bar Camp. Played in 2 Capoeira Rodas in Brazil. Participated in the effort to reboot LA … -
I did an Aú Batido in 2014, now what?
This is my summary of my resolutions for 2014 and an early pass at my resolutions for 2015. I'm doing this right now instead of at the end of the year because as of the afternoon of December 21, I'm going off the grid. Resolutions Accomplished in 2014 Release the second edition of Two Scoops of Django. Visited South America. Visited two new nations, Argentina and Brazil. Went back to the East Coast to visit Philadelphia and places in New Jersey. Went back to the Philippines. Took some awesome road trips around the USA. My favorite was driving up the Pacific Coast Highway. Took a fun class with Audrey. We did woodshop! Learned how to do Aú Batido! General Accomplishments Published Two Scoops of Django 1.6 with my awesome wife, Audrey Roy Greenfeld. Experienced my first major surgery. Started working at Eventbrite. Found a Inland Empire Capoeira group but still remained friends with Capoeira Batuque. Gave talks at: Wharton School of Business Web Conference PyDay Mendoza Python Brazil PyCon Argentina Experienced the unbelievably tasty asado (steak) of Argentina. Participated in organizing the first Django Bar Camp. Played in 2 Capoeira Rodas in Brazil. Participated in the successful effort to reboot … -
Server migration for BotBot.me
End of last week vitaly and I launched a redesign of BotBot.me user account. You can now suport us by subscribing to it for 3$/month and even log personal channel for 2$/month. If you are curious check it out here I would like to share with you the scenario & tactics we used to do this with least service interruption. BotBot.me receives less traffic than most our customers site but it collects hundreds of messages per minutes which lead to interesting challenges. As part of this deployment we were also changing cloud provider. So we needed to move all the underlying infrastructure. Here it is the main services constituing BotBot.me: redis postgresql go IRC client python plugins django web interface We use slatstack to configure our servers. I am not going to present the detailed configuration of each pieces but instead explain the strategy we followed. Reverse Proxy From now on legacy_server is the legacy server and new_server the new server. On this project we use nginx to do the TLS termination, serving static assets and finally reverse proxying the django app. We use autossh to create ssh tunnel from new_server to legacy_server. Here it is an example for redis: … -
Quick Introduction to Mock
Quick Introduction to Mock -
Generate Sphinx Friendly Docstrings For Python Functions In Emacs!
Today, I went to Django REST Framework Workshop. After the workshop is completed, and we were discussing about Emacs, Krace showed this cool plugin sphinx-doc, it inserts docstring skeleton for Python functions/methods as per the requirement of the Sphinx documentation generator.Installation:To install it from MELPA, run "M-x package-list-packages", search for "sphinx-doc" , mark it with i and press x to install.Configuration:Add these lines to Your emacs config to enable sphinx-doc-mode.(add-hook 'python-mode-hook (lambda () (require 'sphinx-doc) (sphinx-doc-mode t)))If you document your code(infact you should), this plugin saves quite a few strokes! -
Quickly Check If Your Django App Is Ready For Production!
Before deploying Your Django app, You need to make sure security, logging and other issues are taken care. Django provides a simple deployment checklist which helps a lot. In development version Django provides --deploy option, which does some security checks. You can run it withpython manage.py check --deploy --settings=production_settingsI have just created a new project and Django identified 6 security issues in it.→ python manage.py check --deploy System check identified some issues:WARNINGS:?: (security.W001) You do not have 'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE_CLASSES so the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_BROWSER_XSS_FILTER, and SECURE_SSL_REDIRECT settings will have no effect.?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE_CLASSES, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF token.?: (security.W017) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE_CLASSES, but you have not set CSRF_COOKIE_HTTPONLY to True. Using an HttpOnly CSRF cookie makes it more difficult for cross-site scripting attacks to steal the CSRF token.?: (security.W018) You should not have DEBUG set … -
Naming things: don't use reserved words
I'm currently cleaning up some code. Some people just cannot spell "p-e-p-8" if their lives depended on it, apparently. Luckily I'm civilized so I only threaten with dismemberment. Look at this gem I just uncovered: tg_after = instance.filter.technischegegevensfilter_set.exclude( pk=instance.pk).filter( datum_vanaf__gt=instance.datum_vanaf).order_by( 'datum_vanaf')[:1] Don't mind about the Dutch in there. Just look at those two filter words in the first two lines. They're even nicely underneath each other. At least they are now, I first had to fit the 159 characters long line within 78 characters, of course. In Django, you do sql filtering with .filter(some_condition=42). That's not what's happening in the first line, though. There's a foreign key called filter there! So the first filter is the name of a foreign key and the second filter is the filter method that is used everywhere in Django. Big confusion. And big chance that someone else that reads the code messes it up somehow. So... steer clear of common words used in your programming language or framework or whatever. Some examples: Don't use type as an name. Use customer_type or station_type or whatever. Only use type by itself if you really mean the python build-in. Don't use class. Either use the standard klass … -
Introducing django-nocaptcha-recaptcha
Introducing django-nocaptcha-recaptcha -
Build a scalable Twitter clone with Django and GetStream.io
Have a look at this tutorial on how to build a scalable twitter clone using django and getstream.io Share and Enjoy: -
Build a scalable Twitter clone with Django and GetStream.io
Build a scalable Twitter clone with Django and GetStream.io -
Building a RESTful API with Django-rest-framework
API's turned to be the heart of every application in our time. With the rise of social media, API's are being developed at a faster pace and gaining a lot of attention. Gone are the days where RPC architectures like CORBA and XML-RPC are used to enable the exchange of information and REST has taken its place making its mark in getting the things pretty straight forward. We use APIs in our everyday life. Take an instance booking a ticket for a movie through some website. Here is the process that takes place in the background. When dealing with the payment for the ticket, the website connects to the bank and sends your credit card details to the remote application and it gets verified. And once, the payment is confirmed by the remote application, it sends a confirmation response to the movie booking website to issue the tickets. The payment stuff turned possible here as the bank facilitates an API through which a website can connect to it and deal with the payments which resulted us an effective and seamless transaction. In this post we will get to know how to build a Restful API for an application using a … -
Caktus Hosts Lightweight Django Book Launch with Girl Develop It
With Girl Develop It RDU, we celebrated the launch of Lightweight Django (O'Reilly) with the authors, Caktus Technical Director Mark Lavin and Caktus alum Julia Elman. Sylvia Richardson of Girl Develop It MCed. The event was open to the public and so popular we kept recounting the RSVPs and fretting over the fire code. But, phew, we were good. In attendance were friends, family, fellow Cakti, and Django fans from around the Triangle. Festivities included lots of Mediterranean food, some of Mark's favorite beers, raffled-off gift bags filled with Caktus goodies, and, for those in the first two rows, free copies of Lightweight Django. The main attraction, of course, was hearing Mark and Julia speak. In response to audience questions, they both emphasized code quality with Mark highlighting the importance of iteration in any process. You can read more about their very strong opinions in Lightweight Django. (See what I did there? I totally just encouraged you to buy it. Go buy it!) They also spoke about the ups and downs of writing, the doubts, and the ways they egged each other on. There too was the challenge of working on client projects full time, writing the rest of the … -
Loading Django FileField and ImageFields from the file system
Loading Django FileField and ImageFields from the file system -
FreshDesk Python API
FreshDesk is a great helpdesk system with a fully functional API. Recently a client asked to integrate FreshDesk into their Django based CRM. I created the Python interface to the API. Here's the gist. -
Parse cloud code, EmberJS & GetStream.io
Today we’ve released a small example app, which shows you how to integrate GetStream.io with Parse cloud code. The example is based on EmberJS and listens to changes in realtime. The demo shows a simple Facebook/Twitter style network where you can Share your View. Go ahead, try the demo and post a nice shot from the city you’re in right now.https://getstream.parseapp.com/#/ The cool bit here is that Parse Cloud code allows you to connect to other hosted platforms. In this case we’re integrating a scalable newsfeed with getstream.io, but you could for instance also hook up something like Algolia for search. The code for the integration, with explanations of how we’re using the Parse Cloud code can be found on Github/getstream/Stream-Example-ParseLet us know in the comments which other integrations you’d like to see. So far our Django, Rails and Laravel integrations are making it extremely easy to integrate a scalable newsfeed in your app. -
Django Dash & WSGI Wrestle Cancelled
Django Dash & WSGI Wrestle Cancelled -
Project Templates with Cookiecutter
When we start new projects we want to solve a problem, not write boilerplate. Cookiecutter helps you to stop writing boilerplate. In this video you will learn what cookiecutter is, and how to create templates so you can save yourself time and effort starting new projects.Watch Now...