Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Automated deployment with Ubuntu, Fabric and Django
A few months ago I started to play with Fabric and the result was a simple script that automates the creation of a new Django project. In the last months I continued my experiments and extended the script to a full stack for creation and deployment of Django projects. As the details behind the script like the project structure that I use and the server setup are a bit long I will keep this post only on the script usage and I will write a follow up one describing the project structure and server. So in a brief the setup that I use consist of Ubuntu as OS, Nginx as web server and uWSGI as application server. The last one is controlled by Upstart. The script is available for download at GitHub. In a wait for more detailed documentation here is a short description of the main tasks and what they do: startproject:<project_name> Creates a new virtual environment Installs the predefined packages(uWSGI, Django and South)) Creates a new Django project from the predefined template Creates different configuration files for development and production environment Initializes new git repository Prompts the user to choose a database type. Then installs database required packages, … -
Django project file structure
As I promised in Automated deployment with Ubuntu, Fabric and Django I will use this post to explain the file structure that I use for my Django projects and what I benefit from it. So here is my project directory tree. The structure ~/workspace/&lt;project_name&gt;/ |-- bin |-- include |-- lib |-- local |-- src |-- .git |-- .gitignore |-- required_packages.txt |-- media |-- static |-- &lt;project_name&gt; | |-- &lt;project_name&gt; | | |-- __init__.py | | |-- settings | | | |-- __init__.py | | | |-- &lt;environment_type&gt;.py | | | |-- local.py | | |-- templates | | |-- urls.py | | |-- views.py | |-- manage.py | |-- wsgi.py |-- &lt;project_name&gt;.development.nginx.local.conf |-- &lt;project_name&gt;.&lt; environment_type&gt;.nginx.uwsgi.conf |-- &lt;project_name&gt;.&lt; environment_type&gt;.uwsgi.conf Explanation At the top I have a directory named as the project and virtual environment inside of it. The benefit from it is complete isolation of the project from the surrounding projects and python packages installed at OS level and ability to install packages without administrator permissions. It also provides an easy way to transfer the project from one system to another using a requirements file. The src folder is where I keep everything that is going to enter the version control … -
Automation, Fabric and Django - presentation
As a follow up post of Automated deployment with Ubuntu, Fabric and Django here are the slides from my presentation on topic "Automation, Fabric and Django". Unfortunately there is no audio podcast but if there is interest I can add some comments about each slide as part of this post. Automation - fabric, django and more from Ilian Iliev If there is anything that need explanation feel free to ask. -
Simple Site Checker and the User-Agent header
Preface: Nine months ago(I can't believe it was that long) I created a script called Simple Site Checker to ease the check of sitemaps for broken links. The script code if publicly available at Github. Yesterday(now when I finally found time to finish this post it must be "A few weeks ago") I decided to run it again on this website and nothing happened - no errors, no warning, nothing. Setting the output level to DEBUG showed the following message "Loading sitemap ..." and exited. Here the fault was mine, I have missed a corner case in the error catching mechanism i.e. when the sitemap URL returns something different from "200 OK" or "500 internal server error". Just a few second and the mistake was fix. Problem and Solution: I ran the script again and what a surprise the sitemap URL was returning "403 Forbidden". At the same time the sitemap was perfectly accessible via my browser. After some thinking I remembered about that some security plugins block the access to the website if there is not User-Agent header supplied. The reason for this is to block the access of simple script. In my case even an empty User-Agent did … -
Functions in Python presentation
Here is my presentation part of the in company Python course. Functions in python from Ilian Iliev The last slide - "Problem to solve" is something like a simple homework. Sample solutions will be uploaded later this week. -
Functions in Python Homework
After some delay(please excuse me for it) here are sample solutions of the problems defined in the presentation Functions in Python. Solutions are also available at GitHub. -
Introduction to Django - presentation
This presentation shows the basics of Django - what is inside the framework and explains the Model-View-Template system. One of the most important parts is a diagram how the request is processed and the response is generated. Shows the project and the application structure and the basic elements - Models, URLs dispatcher, Views and Templates. Introduction to django from Ilian Iliev -
Django for Web Prototyping
Or how to use the benefits of Django template system during the PSD to HTML phase There are two main approaches to start designing a new project - Photoshop mock-up or an HTML prototype. The first one is more traditional and well established in the web industry. The second one is more alternative and (maybe)modern. I remember a video of Jason Fried from 37 Signals where he talks about design and creativity. You can see it at http://davegray.nextslide.com/jason-fried-on-design. There he explains how he stays away from the Photoshop in the initial phase to concetrate on the things that you can interact with instead of focusing on design details. I am not planning to argue which is the better method, the important thing here is that sooner or later you get to the point where you have to start the HTML coding. Unfortunately frequently this happens in a pure HTML/CSS environment outside of the Django project and then we waste some extra amount of time to convert it to Django templates. Wouldn't be awesome if you can give the front-end developers something that they can install/run with a simple command and still to allow them to work in the Django environment … -
Python Interview Question and Answers
For the last few weeks I have been interviewing several people for Python/Django developers so I thought that it might be helpful to show the questions I am asking together with the answers. The reason is ... OK, let me tell you a story first. I remember when one of my university professors introduced to us his professor - the one who thought him. It was a really short visit but I still remember one if the things he said. "Ignorance is not bad, the bad thing is when you do no want to learn." So back to the reason - if you have at least taken care to prepare for the interview, look for a standard questions and their answers and learn them this is a good start. Answering these question may not get you the job you are applying for but learning them will give you some valuable knowledge about Python. This post will include the questions that are Python specific and I'll post the Django question separately. How are arguments passed - by reference of by value? The short answer is "neither", actually it is called "call by object” or “call by sharing"(you can check here for … -
Resurection
Well, as some of you may have seen this blog was on hold for quite a long time. There were multiple reasons mainly my Ph.D. and changing my job but it is back online. So, what is new? As a start this blog is no longer running on wordpress. The reason is that I had some issues with wordpress - the blog was hacked twice due to security holes in wordpress/plugins, it was terribly slow and the code looked like shit. Lots of inline styles and javascript etc. So I made a simple Django based blog that generates static content. Alse we have new design and new domain, the last one much easier to remember ))) Also the comments are now handled by Disquss and the search functinality is provided by Google. The code of the blog, needs some minor cleaning and then it will be released publicly in the next few weeks. Meanwhile you can check my latest post Working with intervals in Python. P.S. I have finally finished my Ph.D. so no more university/reasearch job and hopefully more time for blogging. -
Working with intervals in Python
Brief: Working with intervals in Python is really easy, fast and simple. If you want to learn more just keep reading. Task description: Lets say that the case if the following, you have multiple users and each one of them has achieved different number of points on your website. So you want, to know how many users haven't got any point, how many made between 1 and 50 points, how many between 51 and 100 etc. In addition at 1000 the intervals start increasing by 100 instead of 50. Preparing the intervals: Working with lists in Python is so awesome, so creating the intervals is quite a simple task. intervals = [0] + \ # The zero intervals [x * 50 for x in range(1, 20)] + \ # The 50 intervals [x * 100 for x in range(10, 100)] + \ # The 100 intervals [x * 1000 for x in range(10, 102)] # the 1000 intervals So after running the code above we will have a list with the maximum number of points for each interval. Now it is time to prepare the different buckets that will store the users count. To ease this we are going to … -
Python 3 – Stream Framework
A quick repost for Stream Framework, Python 3 support. Share and Enjoy: -
Phasing Out Django Packages APIv1 & APIv2
It is time to upgrade Django Packages. If you are using the site's APIs in any way, this affects you. This site, maintained by myself and Audrey Roy Greenfeld, is the directory of reusable apps, sites, and tools for Django-powered projects. And the site has been running on Django 1.4.x for about 2.5 years. Which in internet years is forever. It's time to upgrade! Alas, we have a problem. The Problem The first REST API for the project, APIv1 is running on a very old version of django-tastypie (0.9.7) which blocks upgrading the Django version, even to Django 1.5. While we could do a lot of work to migrate upwards to modern django-tastypie, that would require a lot of time that we would rather spend adding new features or making other stuff. More importantly, there are elements to the APIv1's design that we want to change. While we are on the subject of legacy APIs, the second REST API for the project, the mostly undocumented APIv2, is powered by a relatively old version of Django Rest Framework (2.3.8). The design of APIv2 was a bit of an experiement in architectural design, one whose novel approach (API views in individual apps) … -
Phasing Out Django Packages APIv1 & APIv2
It is time to upgrade Django Packages. If you are using the site's APIs in any way, this affects you. This site, maintained by myself and Audrey Roy Greenfeld, is the directory of reusable apps, sites, and tools for Django-powered projects. And the site has been running on Django 1.4.x for about 2.5 years. Which in internet years is forever. It's time to upgrade! Alas, we have a problem. The Problem The first REST API for the project, APIv1 is running on a very old version of django-tastypie (0.9.7) which blocks upgrading the Django version, even to Django 1.5. While we could do a lot of work to migrate upwards to modern django-tastypie, that would require a lot of time that we would rather spend adding new features or making other stuff. More importantly, there are elements to the APIv1's design that we want to change. While we are on the subject of legacy APIs, the second REST API for the project, the mostly undocumented APIv2, is powered by a relatively old version of Django Rest Framework (2.3.8). The design of APIv2 was a bit of an experiement in architectural design, one whose novel approach (API views mixed into standard … -
Django Girls in Cardiff
(From the Django Girls press release) Django Girls is coming very soon to Cardiff - a first Wales edition of the international programming course directed at women. This non-profit event will take place during DjangoCon Europe, a large conference for programmers and will be attended by 45 women and girls who want to learn how to build web applications in just one day. -
Simple Django applications for writing Facebook applications and authentication
Creating Facebook applications or integrating websites with Facebook isn't complex or very time consuming. In case of Django there is for example very big django-facebook package that provides a lot of Facebook related features. Pozytywnie.pl, a company I work with released a set of small applications that were used internally to make Facebook applications as well as Facebook authentication integrations. In this article I'll showcase those applications. -
Informing Users with django.contrib.messages
The messages framework can be bit confusing to wrap your head around at first. Learn the basics of setting successful and error messages and show them to users. See the default django way, then see how to do with django-braces.Watch Now... -
Dying NTP deamons on vsphere vmware machines
We (Nelen & Schuurmans) have quite some servers. Most of them are vmware virtual machines in a vshpere cluster. Once in a while, one or more of the machines got reported by our monitoring tool (zabbix) as having a time drift problem. Weird, as we have NTP running everywhere. And weird if you look at django logfiles and see a negative jump in time all of a sudden. We run ntpd everywhere to keep the time in sync with two windows domain servers. Every time a server drifted, the ntpd daemon turned out to have died. Without leaving any trace in any logfile. ntpd kills itself when the time drift is more than 20 minutes or so, assuming that it hurts more than it helps. There's a switch to prevent this self-killing behaviour, but ntpd killed itself anyway. In the end, an external sysadmin found the problem: One of the physical vsphere host machines (big server, lots of blades) was mis-configured: the ntp daemon on the host machine itself was configured, but it was not configured to automatically start when you start up the server... This host machine started to drift its time, naturally. Several actions vsphere does on a … -
Checking for Python version and Vim version in your .vimrc
Recently I’ve had to adjust a bunch of my dotfiles to support some old (Centos 5) systems which means that I am using a Vim that has Python 2.4 build in… needless to say, it breaks some of my dotfiles So here’s some tips on patching Vim version issues. First, checking if you have Python in your Vim and which version you are using. It returns a version similar to how Vim does it with it’s version. So 204 is the result for Python 2.4, 207 for Python 2.7 and so on. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Check python version if available """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("python") python import vim; from sys import version_info as v; vim.command('let python_version=%d' % (v[0] * 100 + v[1])) else let python_version=0 endif Now we can make plugins/bundles dependend on versions: if python_version >= 205 " Ultisnips requires Vim 2.5 or higher due to the with_statement Bundle 'SirVer/ultisnips' else Bundle "MarcWeber/vim-addon-mw-utils" Bundle "tomtom/tlib_vim" Bundle "garbas/vim-snipmate" endif And checking for the Vim version to see if features are available: if version >= 703 set undofile set undodir=~/.vim/undo set undolevels=10000 call system('mkdir ' . expand('~/.vim/undo')) endif That’s it, the examples can be found in my Vim config: https://github.com/WoLpH/dotfiles/blob/master/_vimrc Link to this post! -
Bangalore Django User Group - Beginners Workshop
During BangPypers december dev sprint Few weeks back, Krace & Siva asked me if I can take a Django workshop. I agreed. They have worked on logistics & scheduled for February at IBM, Domlur.I reached there by 9.30 AM. 26 people attended the session. Due to some problems we started a bit late than what we have planned. Krace, Siva & Ankur assisted a lot during the session.We planned to cover the basics of Django & CRUD operations by building a simple app. We covered basics & simple create view. Due to time constraint we were unable to cover the remaining.Content: https://github.com/ChillarAnand/django-bookmarksSlides: http://chillaranand.github.io/django-bookmarks/ -
A method for rendering templates with Python
I never intended to write a template system for Moya. Originally, I was going to offer a plugin system to use any template format you wish, with Jinja as the default. Jinja was certainly up to the task; it is blindingly fast, with a comfortable Django-like syntax. But it was never going to work exactly how I wanted it to, and since I don't have to be pragmatic on my hobby projects, I decided to re-invent the wheel. Because otherwise, how do we get better wheels? The challenge of writing a template language, I discovered, was keeping the code manageable. If you want to make it both flexible and fast, it can quickly descend in to a mass of special cases and compromises. After a few aborted attempts, I worked out a system that was both flexible and reasonable fast. Not as fast as template systems that compile directly in to Python, but not half bad. Moya's template system is about 10-25% faster than Django templates with a similar feature set. There are a two main steps in rendering a template. First the template needs to be tokenized, i.e. split up in a data structure of text / tags. This … -
A simple method for rendering templates with Python
I never intended to write a template system for Moya. Originally, I was going to offer a plugin system to use any template format you wish, with Jinja as the default. Jinja was certainly up to the task; it is blindingly fast, with a comfortable Django-like syntax. But it was never going to work exactly how I wanted it to, and since I don't have to be pragmatic on my hobby projects, I decided to re-invent the wheel. Because otherwise, how do we get better wheels? The challenge of writing a template language, I discovered, was keeping the code manageable. If you want to make it both flexible and fast, it can quickly descend in to a mass of special cases and compromises. After a few aborted attempts, I worked out a system that was both flexible and reasonable fast. Not as fast as template systems that compile directly in to Python, but not half bad. Moya's template system is about 10-25% faster than Django templates with a similar feature set. There are a two main steps in rendering a template. First the template needs to be tokenized, i.e. split up in a data structure of text / tags. This … -
A simple method for rendering templates with Python
I never intended to write a template system for Moya. Originally, I was going to offer a plugin system to use any template format you wish, with Jinja as the default. Jinja was certainly up to the task; it is blindingly fast, with a comfortable Django-like syntax. But it was never going to work exactly how I wanted it to, and since I don't have to be pragmatic on my hobby projects, I decided to re-invent the wheel. Because otherwise, how do we get better wheels? The challenge of writing a template language, I discovered, was keeping the code manageable. If you want to make it both flexible and fast, it can quickly descend in to a mass of special cases and compromises. After a few aborted attempts, I worked out a system that was both flexible and reasonable fast. Not as fast as template systems that compile directly in to Python, but not half bad. Moya's template system is about 10-25% faster than Django templates with a similar feature set. There are a two main steps in rendering a template. First the template needs to be tokenized, i.e. split up in a data structure of text / tags. This … -
Don't import (too much) in your django settings
One of our production Django sites broke this afternoon with a database error "relation xyz doesn't exist". So: a missing table. Why 1 I helped debugging it and eventually found the cause by doing a select * from south_migrationhistory. This lists the south migrations and lo and behold, a migration had just been applied 25 minutes earlier. The migration name suggested a rename of tables, which of course matches the "missing table" error. Why 2 Cause found. But you have to ask yourself "why" again. So: "why was this migration applied?". Well, someone was working on a bit of database cleanup and refactoring. Naming consistency, proper use of permissions, that sort of thing. Of course, locally in a branch. And on a development database. Now why did the local command result in a migration on the production database? Why 3 So, effectively, "why don't the development settings work as intended"? We normally use settings.py as the production settings and a developmentsettings.py that is used in development. It imports from settings.py and sets the debug mode and development database and so. This project is a bit different in that there's only a settings.py. It does however try to import localsettings.py. This … -
Setup Django on Mac
I took some notes as I set-up Django and Python on a new Macbook running MacOS Yosemite (10.10). By following these steps, you'll have the best tools available - as far as I know - to code some Django apps. For most required applications you can use PIP, MacPorts, Python sources, etc. As a result, you might end-up with a massive mess ! To avoid any issue, I'm using PIP & VirtualEnv so I can easily manage multiple Django projects. To do so, the easiest is to get started with Brew.