Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Filter Your List of Objects in the Admin
Getting the data you need in the admin quickly is important. Learn how to filter not only based on fields, but add your own custom filter as well.Watch Now... -
Pushing through a straw
Recently, a user reported a noticeable delay between sending a command in-game to multiple users and the result of that command appearing to everyone. You didn't notice this when testing alone but I could confirm there was almost a second delay sometimes between entering the command and some users seeing the result. A second is very long for stuff like this. Processing time for a single command is usually in the milliseconds. What was going on? Some background Evennia has two components, the Portal and the Server, running as two separate processes. The basic principle is that players connecting to an Evennia instance connects to the Portal side - this is the outward facing part of Evennia. The connection data and any other input and output will be piped from the Portal to the Server and back again.The main reason for this setup is that it allows us to completely reset the Server component (reloading module data in memory is otherwise error-prone or at least very tricky to make generically work in Python) without anyone getting disconnected from the Portal. On the whole it works very well.DebuggingTracing of timings throughout the entire Server<->Portal pipeline quickly led me to rule out … -
Introduction to Monte Carlo Tree Search
MathJax.Hub.Config({ TeX: { extensions: ["color.js"] }}); For DjangoCon 2015, Jeff Bradberry created an A.I. for our booth game, Ultimate Tic Tac Toe. Reprinted here from jeffbradberry.com is his explanation of the Monte Carlo Tree Search used to build the A.I. The subject of game AI generally begins with so-called perfect information games. These are turn-based games where the players have no information hidden from each other and there is no element of chance in the game mechanics (such as by rolling dice or drawing cards from a shuffled deck). Tic Tac Toe, Connect 4, Checkers, Reversi, Chess, and Go are all games of this type. Because everything in this type of game is fully determined, a tree can, in theory, be constructed that contains all possible outcomes, and a value assigned corresponding to a win or a loss for one of the players. Finding the best possible play, then, is a matter of doing a search on the tree, with the method of choice at each level alternating between picking the maximum value and picking the minimum value, matching the different players' conflicting goals, as the search proceeds down the tree. This algorithm is called Minimax. The problem with Minimax, … -
PyCon 2016: Behind the Design
Having helped to design an award-winning event site for last year’s PyCon in Montreal, we are thrilled to collaborate again with the Python Software Foundation (PSF) on this year’s site for PyCon 2016. PyCon 2016 will be held in Portland, OR and PSF knew they wanted to convey the distinctive mood and look of that city with the 2016 website. Working collaboritively with PSF, Designer Trevor Ray drew on everything from the unique architecture of the city’s craftsman-style bungalow houses and the surrounding mountainous landscape to the cool color scheme of the Pacific-Northwest region. The team developed a site that leads the user on a journey. As he or she scrolls, the user is brought further into the city, from the low, rolling, misty, forest-topped mountains on the outskirts, into the very heart of its neighborhoods. Trevor also redesigned the PyCon logo for 2016, giving it a peaked shape, hand-lettered typography (a reference to the thriving craft community of Portland), and a classic, balanced layout. Ultimately, our team and PSF worked together to achieve a site that we hope is welcoming and functional. We’re excited for this year’s PyCon, and we hope the site excites attendees as well. Only 249 … -
Automate Django Deployments with fabfile
Fabric is a Python library and command-line tool with the ability to execute commands on a remote server. It is designed to use SSH to execute system administration and deployment tasks on one or more remote machines. Usage To automate administration tasks and deployments. Typical usage involves creating a python module containing one or more functions, then executing them via the fab command-line tool. Installation Fabric requires Python version 2.5 or 2.6. The easiest ways of installing Fabric is via, pip, easy_install: $ pip install fabric (OR) $ sudo easy_install fabric (OR) $ sudo apt-get install fabric Fabric Functions Now, we learn about some of the functions in Fabric. Fabric provides a set of commands in fabric.api module: $ local # To execute a local command. $ run # To execute a remote command on all specific hosts, user-level # permissions. $ sudo # To execute a command on the remote server with sudo (i.e. superuser) # privileges. $ put # To copy the local file to a remote destination. $ get # To download a file from the remote server. $ prompt # Prompt user with text and return the input (like raw_input). $ reboot # To reboot the … -
Django Migrations Doesn't Play Nice with Third-Party Stuffs
I ran into something annoying while working on my Tweetpile project the other day and it just happened to me today on Atlas. Sometimes, removing code can cause explosions with migrations -- even when they've already been run. Example: You've created a new class called MyClass. It subclasses models.Model It makes use of a handy mixin you wrote called MyMixin: class MyClass(MyMixin, models.Model): # stuff here You create a migration for it, run it, commit your code and congratulate yourself on code well done. Months later you come back and realise that the use of MyMixin was a terrible mistake, so you remove it. Now migrations don't work anymore. Here's what happened: Creating a migration that's dependent on non-Django-core stuff to assemble the model (think mixins that add fields, or the use of custom fields etc.) means that migrations has to import those modules to run. This is a problem because every time you run manage.py migrate it loads all migration files into memory, and if those files are importing now-non-existent modules, everything breaks. Solution: It's an ugly one, but so far it's the only option I can figure: manually collapsing the migration stack. Basically you make sure you've run … -
Utrecht javascript meetup summaries
Normally I attend python/django meetups, but tonight I attended the Utrecht (=middle of the Netherlands) javascript meetup for the second time. I don't have notes of the first one (that was much too visual to make writing something down worthwile), but this time I have. WebRTC datachannel - Roland van Laar Roland van Laar talks about web applications for education and webrtc data channels. Webrtc is p2p (peer to peer) for browsers. You can use it for audio, video. Datachannel is a bit like p2p websockets. Why did he wanted to use it? Well, he writes educational software. In elementary schools in the Netherlands, that often means a teacher and a digiboard. He showed a demo with a website that showed a six-figure code that the teacher then had to type in on his accompagnying phone app. After thus connecting the webbrowser to the phone, he could then steer the webbrowser from the phone. Advancing sheets, and so. The advantage about webrtc and p2p: it is a direct connection between the phone and the browser, without being dependent on the ofttimes-flaky school's internet connection. How do you build up a connection? The one that starts creates an RTCPeerConnection and creates … -
Automate Django Deployments with fabfile
Fabric is a Python library and command-line tool with the ability to execute commands on a remote server. It is designed to use SSH to execute system administration and deployment tasks on one or more remote machines. Usage To automate administration tasks and deployments. Typical usage involves creating a python module containing one or more functions, then executing them via the fab command-line tool. Installation Fabric requires Python version 2.5 or 2.6. The easiest ways of installing Fabric is via, pip, easy_install: $ pip install fabric (OR) $ sudo easy_install fabric (OR) $ sudo apt-get install fabric Fabric Functions Now, we learn about some of the functions in Fabric. Fabric provides a set of commands in fabric.api module: $ local # To execute a local command. $ run # To execute a remote command on all specific hosts, user-level permissions. $ sudo # To execute a command on the remote server with sudo (i.e. superuser) privileges. $ put # To copy the local file to a remote destination. $ get # To download a file from the remote server. $ prompt # Prompt user with text and return the input (like raw_input). $ reboot # To reboot the remote system, … -
django-semanticui-form
I'm working on a (side)project in Django that uses the awesome Semantic UI CSS framework. This project has some Django forms that are rendered on the server and so I can't let Django render the form HTML or else the CSS framework can't do its magic. The project is called django-semanticui-form and it's a fork from django-bootstrap-form. It doesn't come with the Semantic UI CSS files at all. That's up to you. Semantic UI is available as a big fat bundle (i.e. one big .css file) but generally you just pick the components you want/need. To use it in your Django templates simply, create a django.forms.Form instance and render it like this: {% load semanticui %} <form> {{ myform | semanticui }} </form> The project is very quickly put together. The elements I intend to render seem to work but you might find that certain input elements don't work as nicely. However, if you want to help on the project, it's really easy to write tests and run tests. And Travis and automatic PyPI deployment is all set up so pull requests should be easy. -
django-semanticui-form
I'm working on a (side)project in Django that uses the awesome Semantic UI CSS framework. This project has some Django forms that are rendered on the server and so I can't let Django render the form HTML or else the CSS framework can't do its magic. The project is called django-semanticui-form and it's a fork from django-bootstrap-form. It doesn't come with the Semantic UI CSS files at all. That's up to you. Semantic UI is available as a big fat bundle (i.e. one big .css file) but generally you just pick the components you want/need. To use it in your Django templates simply, create a django.forms.Form instance and render it like this: {% load semanticui %} <form> {{ myform | semanticui }} </form> The project is very quickly put together. The elements I intend to render seem to work but you might find that certain input elements don't work as nicely. However, if you want to help on the project, it's really easy to write tests and run tests. And Travis and automatic PyPI deployment is all set up so pull requests should be easy. -
z3c.recipe.usercrontab ported to python 3
z3c.recipe.usercrontab is a simple buildout recipe to add content to your buildout user's crontab. Our django sites often have something like this in our buildout configs, just to give you an idea of what you can do with it: [supervisor-cronjob] # Start supervisor (which in turn starts django and celery) # when the server starts. recipe = z3c.recipe.usercrontab times = @reboot command = ${buildout:bin-directory}/supervisord [django-session-cleanup-cronjob] recipe = z3c.recipe.usercrontab times = 14 3 * * * command = ${buildout:bin-directory}/django clearsessions Easy peasy. Especially starting the site @reboot is handy. You could also add an entry in /etc/init.d/your_site, but this way most of the setup of the site is handled for you by a single bin/buildout call. The previous release was in 2010: it simply didn't need any changes, it just performed the job it did and did it well :-) Now I've made a few small changes, mostly in the test code. Another package ported to python 3! -
django-registration updates
Since announcing its resurrection a couple weeks ago, I’ve been working on django-registration pretty much continuously. There are over 30 commits since that last post, and I think it’s finally getting close to release quality; what’s left at this point is, I think, mostly stylistic cleanups and editing and pushing some more documentation. There are a couple big highlights from the past few weeks’ work, and I’d like to take a moment to go over those ... Read full entry -
django-registration updates
Since announcing its resurrection a couple weeks ago, I’ve been working on django-registration pretty much continuously. There are over 30 commits since that last post, and I think it’s finally getting close to release quality; what’s left at this point is, I think, mostly stylistic cleanups and editing and pushing some more documentation. There are a couple big highlights from the past few weeks’ work, and I’d like to take a moment to go over those ... Read full entry -
Caktus at DjangoCon 2015
Django is kind of our thing, so we’ve been looking forward to DjangoCon 2015 for months! Now that it is finally here, we thought we would give a little preview of what Cakti will be up to at this year’s conference. Tuesday: Django Authors Panel (1:30 pm) Meet Caktus Technical Director and co-author of Lightweight Django Mark Lavin at this panel of people who write about Django. Learn about the experience of writing or recording video about Django from a collection of talented tech authors! Wednesday: Intro to Client-Side Testing (11:50 am) You've just built a REST API and client-side application to consume it. With all your focus on architecture, you missed a critical piece: how do you test it? In this intermediate-level talk, Mark Lavin will look at some of the tools available to test this style of application with both Javascript unit tests and integration tests written in Python. Wednesday: Lightweight Django Book Signing (2:50 pm) Come meet co-author of Lightweight Django Mark Lavin and have him sign your copy. You can also say hello to everyone at our Caktus Group table! Thursday: DjangoGirls Austin Workshop (9:00 am) We’re a proud DjangoGirls sponsor and organizer of DjangoGirls RDU. … -
Automation for better behaviour
Now... that's a provocative title! In a sense, it is intended that way. Some behaviour is better than other behaviour. A value judgment! In the Netherlands, where I live, value judgments are suspect. If you have a comment on someone's behaviour, a common question is whether you're "better" than them. If you have a judgment, you apparently automatically think you've got a higher social status or a higher moral standing. And that's bad, apparently. Well, I despise such thinking :-) Absolute values I think there are absolutes you can refer to, that you can compare to. Lofty goals you can try to accomplish. Obvious truths (which can theoretically be wrong...) that are recognized by many. Nihilism is fine, btw. If you're a pure nihilist: I can respect that. It is an internally-logical viewpoint. Only you shouldn't complain if some other nihilist cuts you to pieces if that suits his purely-individual nihilistic purposes. So for practical purposes I'm going to assume there's some higher goal/law/purpose/whatever that we should attain. Take programming in python. PEP 8, python's official style guide is recognized by most of the python programmers as the style guide they should adhere to. At least, nobody in my company … -
GoDjango Podcast Episode 1 - Interview with Luke Crouch
Listen in as we talk to Luke Crouch about upgrading from Django 1.4 to 1.7, MDN and discuss a potential move from a dedicated data center to AWS. -
How to make one view do the work of two
Hey folks! Today's is an interesting topic: making one view do two functions. In fact, you can make it do more than two; you an make them do 8 at a time. Think of it as view overloading, if you're into that kind of thing.So let's dive into it.Take logging into your account for example. Initially what I used to do is split this process into three views: one for displaying the login page, one for verification of credentials, and a third for displaying the profile. With the new method I will outline in this post you can do that using only two views rather than three. We'll combine displaying the login page and credential verification into one view. The way well do that will use HTTP request methods. Let's see what those are (going to take a little help from TutorialsPoint for the exact definitions):GET: This method is used to extract data that is embedded in the URL. The data is identified by a '?'. For example, in the URL "http://some.url/?data1=value1&data2=value2" the data after the '?' can be translated as {'data1':'value1', 'data2':'value2'}HEAD: This one is the same as GET, but this one only transfers status line and header sectionPOST: … -
Lessons learned from buildout a django site with a reactjs front-end
My colleague Gijs Nijholt just posted his blog entry lessons learned from building a larger app with React.js, which is about the javascript/reactjs side of a django website we both (plus another colleague) recently worked on. Simplified a bit, the origin is a big pile of measurement data, imported from csv and xml files. Just a huge list of measurements, each with a pointer to a location, parameter, unit, named area, and so on. A relatively simple data model. The core purpose of the site is threefold: Import, store and export the data. Csv/xml, basically. Select a subset of the data. Show the subset in a table, on a map or visualized as graphs. The whole import, store, export is where Django shines. The model layer with its friendly and powerful ORM works fine for this kind of relational data. With a bit of work, the admin can be configured so that you can view and edit the data. Mostly "view" as the data is generally imported automatically. Which means you discover possible errors like "why isn't this data shown" and "why is it shown in the wrong location". With the right search configuration and filters, you can drill down … -
Chicago Djangonauts meetup Sep 3, 2015
Chicago Djangonauts meetup Sep 3, 2015 -
A wagon-load of post-summer updates
Summer vacations are over and work resumes in Evennia land! Here's a wagon-load of small updates on what's going on. Ainneve The Ainneve project, the creation of an official, open-source Evennia demo game, has gotten going. The lead devs of the project are keen to make this a collaborative effort and there is a lot of good discussion and code being written. After some slowdown at the end of summer it's bound to pick up again. Ainneve's a rare chance to see a full MUD getting developed from scratch out in the open. The current issue list includes tags for difficulty and allows also newbie Python coders to jump in. Not to mention you have a chance to get valuable feedback on your work by seasoned coders! So if you are at all interested in making a MUD, try out Python/Evennia or just get involved in a semi-big programming project, this is a great chance to do so.Imaginary RealitiesSince a few weeks, there is a new issue of Imaginary realities (vol 7, issue 3) is out. As usual I have an article in it. This venerable e-zine was revitalized to include articles on both MU* as well as roguelikes, Interactive … -
Easy maintainance: script that prints out repair steps
At my work we have quite a number of different sites/apps. Sometimes it is just a regular django website. Sometimes django + celery. Sometimes it also has extra django management commands, running from cronjobs. Sometimes Redis is used. Sometimes there are a couple of servers working together.... Anyway, life is interesting if you're the one that people go to when something is (inexplicably) broken :-) What are the moving parts? What do you need to check? Running top to see if there's a stuck process running at 100% CPU. Or if something eats up all the memory. df -h to check for a disk that's full. Or looking at performance graphs in Zabbix. Checking our "sentry" instance for error messages. And so on. You can solve the common problems that way. Restart a stuck server, clean up some files. But what about a website that depends on background jobs, run periodically from celery? If there are 10 similar processes stuck? Can you kill them all? Will they restart? I had just such a problem a while ago. So I sat down with the developer. Three things came out of it. I was told I could just kill the smaller processes. … -
Testing SaltStack with Vagrant
Testing SaltStack with Vagrant -
Runs on python 3: checkoutmanager
Checkoutmanager is a five-year old tool that I still use daily. The idea? A simple ~/.checkoutmanager.cfg ini file that lists your checkouts/clones. Like this (only much longer): [local] vcs = git basedir = ~/local/ checkouts = git@github.com:nens/syseggrecipe.git git@github.com:buildout/buildout.git git@github.com:reinout/reinout-media.git git@github.com:rvanlaar/djangorecipe.git [svn] vcs = svn basedir = ~/svn/ checkouts = svn+ssh://reinout@svn.zope.org/repos/main/z3c.recipe.usercrontab/trunk In the morning, I'll normally do a checkoutmanager up and it'll go through the list and do svn up, git pull, hg pull -u, depending on the version control system. Much better than going though a number of them by hand! Regularly, I'll do checkoutmanager st to see if I've got something I still need to commit. If you just work on one project, no problem. But if you need to do quick fixes on several projects and perhaps also store your laptop's configuration in git... it is easy to forget something: $ checkoutmanager st /Users/reinout/vm/veertien/efcis-site M README.rst And did you ever commit something but forgot to push it to the server? checkoutmanager out tells you if you did :-) Porting to python 3. The repo was originally on bitbucket, but nowadays I keep having to look all over my screen, looking for buttons, to get anything done there. I'm … -
Getting Started with Django Admin
The admin is a very useful tool for developers to use when working with django. It is super easy to setup, and get your models registered with it so you can start CRUDing data.Watch Now... -
Making Clean Code a Part of Your Build Process (And More!)
At Caktus, "clean" (in addition to "working"!) code is an important part of our delivery. For all new projects, we achieve that by using flake8. flake8 is a wrapper around several tools: pep8, pyflakes, and McCabe. pep8 checks to make sure your code matches the PEP 0008 style guidelines, pyflakes looks for a few additional things like unused imports or variables, and McCabe raises warnings about overly complex sections of code. We usually check code formatting locally before committing, but we also have safety checks in place in case someone forgets (as I more than anyone have been known to do!). This prevents code formatting standards from slowly eroding over time. We accomplish this by making our continuous integration (CI) server "fail" the build if unclean code is committed. For example, using Travis CI, simply adding the following line to the script: section of your .travis.yml will fail the build if flake8 detects any formatting issues (the command returns a non-zero exit code if errors are found): - flake8 . You can adjust flake8 defaults by adding a file named setup.cfg to the top level of your repository. For example, we usually relax the 80 character limit a little and …