Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
2016 DBIR Highlights
The 2016 edition of Verizon’s Data Breach Investigations Report is out, and as usual it’s compelling reading. The DBIR is one of the only sources of hard data about information security, which makes it a must-read for anyone trying to run a security program in a data-driven manner. What follows are the bits that I found especially interesting, and a bit of my own commentary. Internal threats are rare [T]he Actors in breaches are predominantly external. -
Florida Open Debate Site Powers First-Ever Crowd-Sourced Open Senate Debate
Florida Open Debate launched ahead of the upcoming, bi-partisan debate between candidates for the Florida Senate. The site, which crowdsources debate questions from the general public, was met with national acclaim. Citizens can not only submit questions, but also vote on which ones matter most. Caktus helped develop the tool on behalf of the Open Debate Coalition (ODC), a non-partisan organization dedicated to supporting participatory democracy through the use of civic tech. -
Django: Running management commands inside a Docker container
Okay, so we have dockerized our django app and we need to run a manage.py command for some task. How do we do that? Simple, we have to locate the container that runs the django app, login and then run the command. Locate The Container It’s very likely that our app uses multiple containers to compose the entire system. For exmaple, I have one container running MySQL, one container running Redis and another running the actual Django app. If we want to run manage.py commands, we have to login to the one that runs Django. While our app is running, we can find the running docker containers using the docker ps command like this: $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 308f40bba888 crawler_testscript "/sbin/my_init" 31 hours ago Up 3 seconds 5000/tcp crawler_testscript_1 3a5ccc872215 crawler_web "bash run_web.sh" 31 hours ago Up 4 seconds 0.0.0.0:8000->8000/tcp crawler_web_1 14f0e260fb2c redis:latest "/entrypoint.sh redis" 31 hours ago Up 4 seconds 0.0.0.0:6379->6379/tcp crawler_redis_1 252a7092870d mysql:latest "/entrypoint.sh mysql" 31 hours ago Up 4 seconds 0.0.0.0:3306->3306/tcp crawler_mysql_1 In my case, I am using Docker Compose and I know my Django app runs using the crawler_web image. So we note the name of the container. In … -
A reading list for InfoSec engineers
I’ve started a curated reading list for InfoSec engineers. I was inspired by Mark McGranaghan’s Services Engineering reading list. I really enjoy these kinds of personal, highly-curated reading lists, and for some time I’ve wanted to pull together one of my own. This is my list, not a definitive one — that is, these are resources I’ve found useful. As such it has some biases: It’s oriented towards providers of Software-, Platform-, and Infrastructure-as-a-Service. -
Django REST Framework: Remember to disable Web Browsable API in Production
So this is what happened – I built an url shortening service at work for internal use. It’s a very basic app – shortens urls and tracks clicks. Two models – URL and URLVisit. URL model contains the full url, slug for the short url, created time etc. URLVisit has information related to the click, like user IP, browser data, click time etc and a ForeignKey to URL as expected. Two different apps were using this service, one from me, another from a different team. So I kept the Web Browsable API so the developers from other teams can try it out easily and they were very happy about it. The only job of this app was url shortening so I didn’t bother building a different home page. When people requested the / page on the domain, I would redirect them directly to /api/. Things were going really great initially. There was not very heavy load on the service. Roughly 50-100 requests per second. I would call that minimal load. The server also had decent hardware and was running on an EC2 instance from AWS. nginx was on the front while the app was run with uwsgi. Everything was so … -
Psychological safety in the InfoSec industry
My co-worker Eric Mill recently brought up the topic of psychological safety. Referencing a study by Google that points to psychological safety as a key factor in successful teams, Eric wrote: Maybe these situations sounds familiar to others (they definitely both are to me): Did you feel like you could ask what the goal was without the risk of sounding like you’re the only one out of the loop? -
From Intern to Professional Developer: Advice on a Mid-Career Pivot
A few weeks ago, Rebecca Conley attended DjangoCon Europe 2016 in Budapest, Hungary. The event is a five-day conference that brings together Django lovers from all over the world to learn about and share each other’s experiences with Django. -
Adopting Scrum in a Client-services, Multi-project Organization
Caktus began the process of adopting Scrum mid-November 2015 with two days of onsite Scrum training and fully transitioned to a Scrum environment in January 2016. From our original epiphany of “Yes! We want Scrum!” to the beginning of our first sprint, it took us six weeks to design and execute a process and transition plan. This is how we did it: -
What We're Clicking - March Link Roundup
We’re starting a new, monthly series on the Caktus blog highlighting the articles and posts shared by Cakti that drew the most attention on Twitter. These roundups will include everything from Django how-tos to explorations of the tech industry, to innovations for social good. -
New white paper: "Shipping faster: Django team improvements"
For the past couple months, we’ve been working on a new white paper, “Shipping Faster: Django Team Improvements”. We examined our existing processes, looked at best practices, and considered what has or hasn’t worked across our dozens of simultaneous projects. -
Lightweight Django now in Portuguese!
We’re proud to report that Lightweight Django (O’Reilly Media) is now available in Portuguese as Django Essencial. The book was written by our technical director Mark Lavin and Caktus alumnus Julia Elman to great reviews. Django Essencial comes just in time for Mark’s keynote talk during PyCon Nordeste. -
Lightweight Django now in Portuguese!
We're proud to report that Lightweight Django (O'Reilly Media) is now available in Portuguese as Django Essencial. The book was written by our technical director Mark Lavin and Caktus alumnus Julia Elman to great reviews. Django Essencial comes just in time for Mark's keynote talk during PyCon Nordeste. Purchase Django Essencial here. -
Braintree Integration with Django
Braintree Integration with Django -
Checking That It's All Translatable
When building a translated application, it's important to test that all of the text is going to be translated, but difficult to tell until the translation has been done. Until then, even when you switch languages you still see English everywhere. It's not until all the text that's been set up to be translated actually is that you can see the site in the other language, at which point the English messages stick out like a sore thumb. But that's usually very late in the process. How can we catch those errors earlier? -
A side-by-side Comparison of Django and Moya
The Django code in this post comes from the official Django tutorial. I've tried not to be disingenuous with the comparison, and I'm only going to compare like with like, so I can show code from both frameworks and let you draw your own conclusions. I'll cover the areas where they differ in another post. Models Both Moya and Django use models to map databases on to familiar data structures. In the case of Moya, the mapping is done with SQLAlchemy. Django uses its own ORM. Here's the models.py from the Django tutorial and a Moya version: models.py import datetime from django.db import models from django.utils import timezone class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) class Choice(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def __str__(self): return self.choice_text models.xml <moya> <model libname="Question" repr="question_text" xmlns="http://moyaproject.com/db"> <string name="question_text" length="200"/> <datetime name="pub_date" label="date published"/> <property name="was_published_recently" expression="pub_date gte .now - 1d"/> </model> <model libname="Choice" repr="choice_text" xmlns="http://moyaproject.com/db"> <foreign-key name="question" model="#Question" backref="choices" owned="yes"/> <string name="choice_text" length="200"/> <integer name="votes" default="0"/> </model> </moya> You may have noticed that there is nothing comparable to Python's import statements in the Moya code. … -
Building a location aware web app with GeoDjango
PostgreSQL has excellent support for geographical data thanks to the PostGIS extension, and Django allows you to take full advantage of it thanks to GeoDjango. In this tutorial, I’ll show you how to use GeoDjango to build a web app that allows users to search for gigs and events near them. Requirements I’ve made the jump to Python 3, and if you haven’t done so yet, I highly recommend it - it’s not hard, and there’s very few modules left that haven’t been ported across. As such, this tutorial assumes you’re using Python 3. You’ll also need to have Git, PostgreSQL and PostGIS installed - I’ll leave the details of doing so up to you as it varies by platform, but you can generally do so easily with a package manager on most Linux distros. On Mac OS X I recommend using Homebrew. If you’re on Windows I think your best bet is probably to use a Vagrant VM. We’ll be using Django 1.9 - if by the time you read this a newer version of Django is out, it’s quite possible that some things may have changed and you’ll need to work around any problems caused. Generally search engines … -
Create Cache Bustable Static Files
Dealing with static files like css and javascript and the cache can be annoying, and hard. Fortunately Django provides a way to solve this fairly easily. Learn how to add a hash in your static file names so caching can be easier.Watch Now... -
Technical stuff happening
Hi folks, a bit more technical entry this time. These usually go onto the Evennia mailing list but I thought it would be interesting to put it in the dev-blog for once. So, I'm now halfway through the TODO list issue of the wclient development branch as alluded to in the last post. The wclient branch aims to rework and beef up the web client infrastructure of Evennia.The first steps, which has been done a while was converting the SSH/SSL and IRC input/output protocols to use the new protocol infrastructure (telnet and websockets was done since before). That's just under-the-hood stuff though. Today I finished the changes to the Monitor/TickerHandlers, which may be of more general interest. With the changes to the the way OOB (Out-Of-Band) messages are passing through Evennia (see this mailing list post for more details), the OOBHandler is no more. As discussed there, the handling of incoming data is becoming a lot freer and will be easily expandable to everyone wanting to make for a custom client experience. The idea is thus for Evennia to offer resources for various input commands to make use of, rather than prescribing such functionality in a monolothic way in the … -
Caktus Internship Fuels a Career Re-Launch
What is it like to be an intern at Caktus? I am finishing up as the spring Django intern (though I didn't actually use any Django), so I'll share my experience. What brought me to this point As a long-time stay-at-home mom re-entering the workforce, I was apprehensive about how my lack of recent professional work experience and references would affect my job search. To update my skillset, I completed the intensive 12-week Python course at The Iron Yard. I was hoping to find work in the tech industry I had left behind before having three children. I was fortunate to be offered a 12-week part-time internship at Caktus. On my application and in my interview, I had expressed an interest in exploring HTML and CSS in more depth than I had had a chance to do at The Iron Yard. And that is how I have spent the majority of my time here. My first task was to implement a style guide for the Caktus website. A generic style guide existed but needed to be customized to reflect the Caktus website. What is a style guide? Style guides do several things: Give direction to designers and developers about the … -
Django + Celery & Rabbit - part four
This is the fourth part of Celery and RabbitMQ in Django series. Today I will fix minor bugs and sum up this series. Audio File detail view This is the first bug that I wanted to tackle. Did you remember my last post ? At the end there was a bug show below: The problem was after successful upload django redirect to detail view of uploaded file. And in HTML template of this view, it expects that ac3_file will be there but FFmpeg still is transcoding it. So I came up with solution: 1.First, I added new field to AudioFile model called was_processed to indicate whenever file has been processed: class AudioFile(models.Model): # .... was_processed = models.BooleanField(default=False) By default, this field has value False. 2.Then in my task I added signal handler that ran after every task: from celery.signals import task_postrun @task_postrun.connect def task_executed_handler(sender=None, body=None, **kwargs): audio_file = AudioFile.objects.get(id=kwargs['args'][0]) audio_file.was_processed = True audio_file.save() In this handler id of AudioFile object is taken from kwargs. After retrieving certain file from the database, the flag was_processed is set. 3.Lastly, in my audiofile_detail.html I added this code: {% if object.was_processed %} <ul><a href="{{ object.ac3_file.url}}">Ac3 File</a></ul> <ul><a href="{{ object.ogg_file.url}}">Ogg File</a></ul> <ul><a href="{{ object.wav_file.url}}">Wav File</a><ul> … -
Django + Celery & Rabbit - part four
This is the fourth part of Celery and RabbitMQ in Django series. Today I will fix minor bugs and sum up this series. Audio File detail view This is the first bug that I wanted to tackle. Did you remember my last post ? At the end there was a bug show below: The problem was after successful upload django redirect to detail view of uploaded file. And in HTML template of this view, it expects that ac3_file will be there but FFmpeg still is transcoding it. So I came up with solution: 1.First, I added new field to AudioFile model called was_processed to indicate whenever file has been processed: class AudioFile(models.Model): # .... was_processed = models.BooleanField(default=False) By default, this field has value False. 2.Then in my task I added signal handler that ran after every task: from celery.signals import task_postrun @task_postrun.connect def task_executed_handler(sender=None, body=None, **kwargs): audio_file = AudioFile.objects.get(id=kwargs['args'][0]) audio_file.was_processed = True audio_file.save() In this handler id of AudioFile object is taken from kwargs. After retrieving certain file from the database, the flag was_processed is set. 3.Lastly, in my audiofile_detail.html I added this code: {% if object.was_processed %} <ul><a href="{{ object.ac3_file.url}}">Ac3 File</a></ul> <ul><a href="{{ object.ogg_file.url}}">Ogg File</a></ul> <ul><a href="{{ object.wav_file.url}}">Wav File</a><ul> … -
Django + Celery & Rabbit - part four
Fourth part of series about Django application with Celery and RabbitMQ. -
Django Life – Session 4 (Bangla Screencast)
The audio is in Bangla, you can switch to HD video by toggling the youtube settings. -
Best Python Libraries
Our love for Python is no secret. But with so many modules, tools, and libraries, it can be overwhelming for beginning developers to identify the most useful. Obviously, our favorite framework is Django. But we’re setting aside our undying love for that framework for a moment to offer a list of other helpful Python libraries. From those offering standard solutions to everyday programming problems, to ones that hold a special place in the heart of the dev who created them, these are some of our developer’s favorite tools for Python development. -
Buildout/setuptools speed improvement
Sometimes buildout can seem to hang almost forever, even though you've set a timeout. It happens when installing the project itself. Buildout effectively calls python setup.py develop on your project. Setuptools then first calls os.walk() and builds a complete list of files. Only then does it read your MANIFEST.in and some setup.py settings to determine which files to exclude and include. If you have lots of files inside your directory, this might take a long time. The key thing here is that it first builds a complete list. This includes that BUILDOUT_DIR/var/something directory with 245.934 files. And the BUILDOUT_DIR/node_modules/ with your full npm-downloaded stack of javascript with 10.000 files. And the BUILDOUT_DIR/var/project/ symlink to some slow windows share. Ouch. A buildout that normally takes half a minute can take two hours this way... The setuptools bug reports: https://bitbucket.org/pypa/setuptools/issues/249/have-a-way-to-ingore-specific-dirs-when https://bitbucket.org/pypa/setuptools/issues/450/egg_info-command-is-very-slow-if-there-are Intermediate solution: place this monkeypatch_setuptools.py next to your setup.py: import os TO_OMIT = ['var', '.git', 'parts', 'bower_components', 'node_modules', 'eggs', 'bin', 'develop-eggs'] orig_os_walk = os.walk def patched_os_walk(path, *args, **kwargs): for (dirpath, dirnames, filenames) in orig_os_walk(path, *args, **kwargs): if '.git' in dirnames: # We're probably in our own root directory. print("MONKEY PATCH: omitting a few directories like var/...") dirnames[:] = list(set(dirnames) - set(TO_OMIT)) …