Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Test multiple user accounts without logging out
Have you ever needed to test multiple user accounts in your web app? If you need to check your permissions are working correctly, you might find you are constantly switching users by logging in and logging out. Or you could have an admin user signed in to Chrome, and another user signed in to Firefox. Either way, its a bit of a pain. Here's a simpler solution; define multiple aliases to 127.0.0.1 in your /etc/hosts file. That way you can have one tab open at http://adminuser:8000/ and another open at http://user1:8000/ with two entirely different user accounts. This assumes of course that you have a development server running locally, and that your app is configured to serve to these 'domains'. For example (append this to /etc/hosts): 127.0.0.1 adminuser 127.0.0.1 user1 127.0.0.1 user2 Not sure if this trick is common knowledge. But it literally just occurred to me. -
Django + Celery & Rabbit - part three
This is a third part of Celery and RabbitMQ in Django series. Today I will be building the Celery and RabbitMQ stack. In previous 2 posts: Django + Celery & RabbitMQ part one and Django + Celery & RabbitMQ part two I have made simple application and played with ffmpeg. First: why we need Celery? Imagine that user upload mp3 file to the application and then in form validation the file is transcoded to other formats. The problem is that user will have to wait for the end of a task. So user sends a request. Then he waits for ffmpeg to transcode uploaded file to different format and then sends the response back. At first glance, it may look correct. But imagine that there are big files to transcode or there is a lot of formats to transcode. The user will have to wait a lot of time. To avoid this I will use celery task with rabbitmq broker to provide transcoding in the background. So what is exactly celery? From the docs: Celery is a simple, flexible and reliable distributed system to process vast amounts of messages, while providing operations with the tools required to maintain such a … -
Django + Celery & Rabbit - part three
This is a third part of Celery and RabbitMQ in Django series. Today I will be building the Celery and RabbitMQ stack. In previous 2 posts: Django + Celery & RabbitMQ part one and Django + Celery & RabbitMQ part two I have made simple application and played with ffmpeg. First: why we need Celery? Imagine that user upload mp3 file to the application and then in form validation the file is transcoded to other formats. The problem is that user will have to wait for the end of a task. So user sends a request. Then he waits for ffmpeg to transcode uploaded file to different format and then sends the response back. At first glance, it may look correct. But imagine that there are big files to transcode or there is a lot of formats to transcode. The user will have to wait a lot of time. To avoid this I will use celery task with rabbitmq broker to provide transcoding in the background. So what is exactly celery? From the docs: Celery is a simple, flexible and reliable distributed system to process vast amounts of messages, while providing operations with the tools required to maintain such a … -
Django + Celery & Rabbit - part three
Third part of series about Django application with Celery and RabbitMQ. -
Recommended Django libraries
My two favorite things about Django are Python and the quality of the plugins (which reflects on the quality of Django itself and its community). Here is my personal top 5 of the most useful Django libraries. -
[Django Tips] Make Deleting Easy In Admin!
Lets say we have a model as shown in some project.from django.db import modelsclass Resource(models.Model): """ Model to hold resources for books. """ book = models.ForeignKey('Book') book_type = models.IntegerField() url = models.URLField()This model can be registered in admin as follows.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): list_display = ('book', 'book_type', 'url')admin.site.register(models.Resource, ResourceAdmin)This will generate a nice admin interface to modify the data.Now if we want to delete a record, we need to follow these steps.First, we have to select that recordNext, we have to click on the action dropdownNext, we have to select delete actionNext, we have to click Go button.In the next page we have to confirm that we have to delete.Just to delete a single record, we have to click 5 times. That's too many clicks for a single action.To simplify the process, we can have simple delete button for the objects as shown. This can be achieved by writing a function which will insert delete button for every record.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): def delete(self, obj): return '<input type="button" value="Delete" onclick="location.href=\'%s/delete/\'" />'.format(obj.pk) delete.allow_tags = True delete.short_description = 'Delete object' list_display = ('book', 'book_type', 'url', 'delete')admin.site.register(models.Book)Now we have an admin with delete button for the records.To delete an object, just … -
Django Class-Based Views: The Basics
Django Class-Based Views: The Basics -
Django Tips & Tricks #6 - Make Deleting Easy In Admin
Lets say we have a model as shown in some project.from django.db import modelsclass Resource(models.Model): """ Model to hold resources for books. """ book = models.ForeignKey('Book') book_type = models.IntegerField() url = models.URLField()This model can be registered in admin as follows.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): list_display = ('book', 'book_type', 'url')admin.site.register(models.Resource, ResourceAdmin)This will generate a nice admin interface to modify the data.Now if we want to delete a record, we need to follow these steps.First, we have to select that recordNext, we have to click on the action dropdownNext, we have to select delete actionNext, we have to click Go button.In the next page we have to confirm that we have to delete.Just to delete a single record, we have to click 5 times. That's too many clicks for a single action.To simplify the process, we can have simple delete button for the objects as shown. This can be achieved by writing a function which will insert delete button for every record.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): def delete(self, obj): return '<input type="button" value="Delete" onclick="location.href=\'%s/delete/\'" />'.format(obj.pk) delete.allow_tags = True delete.short_description = 'Delete object' list_display = ('book', 'book_type', 'url', 'delete')admin.site.register(models.Book)Now we have an admin with delete button for … -
Django Tips & Tricks #6 - Make Deleting Easy In Admin
Lets say we have a model as shown in some project.from django.db import modelsclass Resource(models.Model): """ Model to hold resources for books. """ book = models.ForeignKey('Book') book_type = models.IntegerField() url = models.URLField()This model can be registered in admin as follows.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): list_display = ('book', 'book_type', 'url')admin.site.register(models.Resource, ResourceAdmin)This will generate a nice admin interface to modify the data.Now if we want to delete a record, we need to follow these steps.First, we have to select that recordNext, we have to click on the action dropdownNext, we have to select delete actionNext, we have to click Go button.In the next page we have to confirm that we have to delete.Just to delete a single record, we have to click 5 times. That's too many clicks for a single action.To simplify the process, we can have simple delete button for the objects as shown. This can be achieved by writing a function which will insert delete button for every record.from django.contrib import adminfrom . import modelsclass ResourceAdmin(admin.ModelAdmin): def delete(self, obj): return '<input type="button" value="Delete" onclick="location.href=\'%s/delete/\'" />'.format(obj.pk) delete.allow_tags = True delete.short_description = 'Delete object' list_display = ('book', 'book_type', 'url', 'delete')admin.site.register(models.Book)Now we have an admin with delete button for … -
Django + Celery & Rabbit - part two
Hello, today post is the second one in series about Celery in Django. Today I write about ffmpeg. In my application transcoding will be performed by ffmpeg. Why is that? First of all, it's free & open source. So I don't have to pay to use it and I like using the open source tools. Second thing is that ffmpeg is more than enough for my task. It has a lot of features including recording, streaming and transcoding both video and audio. So how to use it? For this project, the ffmpeg needs to be compiled with libmp3lame for mp3 files encoding, libvorbis for ogg format and enabled non-free for ac3. There is guide on ffmpeg site how to compile ffmpeg build. Also, make sure that you have cookies and tea with you while installation can take even 30 minutes. After everything is setup all you need to do is: $ ffmpeg -i mp3_file.mp3 wav_file.wav $ ffmpeg -i mp3_file.mp3 ogg_file.ogg $ ffmpeg -i mp3_file.mp3 ac3_file.ac3 The code above will transcode mp3 files into provided format. In my application one celery task will be called with subprocess, then another celery task will save the output of the first task to django … -
Django + Celery & Rabbit - part two
Hello, today post is the second one in series about Celery in Django. Today I write about ffmpeg. In my application transcoding will be performed by ffmpeg. Why is that? First of all, it's free & open source. So I don't have to pay to use it and I like using the open source tools. Second thing is that ffmpeg is more than enough for my task. It has a lot of features including recording, streaming and transcoding both video and audio. So how to use it? For this project, the ffmpeg needs to be compiled with libmp3lame for mp3 files encoding, libvorbis for ogg format and enabled non-free for ac3. There is guide on ffmpeg site how to compile ffmpeg build. Also, make sure that you have cookies and tea with you while installation can take even 30 minutes. After everything is setup all you need to do is: $ ffmpeg -i mp3_file.mp3 wav_file.wav $ ffmpeg -i mp3_file.mp3 ogg_file.ogg $ ffmpeg -i mp3_file.mp3 ac3_file.ac3 The code above will transcode mp3 files into provided format. In my application one celery task will be called with subprocess, then another celery task will save the output of the first task to django … -
Django + Celery & Rabbit - part two
Second part of series about Django application with Celery and RabbitMQ. -
Class Based Views: The Basics
Class Based Views: The Basics -
Mercurial Mirror For Django 1.9 branch
I forgot to mention it, but I’ve created the 1.9 “production” mirror at the usual location: As a reminder, those mirrors have two purposes: be a lightweight read-only repository to clone from for production servers hide the ugly git stuff behind a great mercurial interface The clone is at the usual location at bitbucket, from which […] -
Django + Celery & Rabbit - part one
Hello, today post is first one in series about Celery in Django application and how to use it. What you gain after reading such series? How to integrate celery + rabbitmq in basic Django application. So what will be our basic application? It is planned to be web service where you can upload mp3 file and then have them transcoded into ogg, wav and ac3 files. I wanted to make easy and in the same time sophisticated project. Recently I started reading an excellent book called Two Scoops of Django: Best Practices for Django 1.8. The book is about what to do and what not to do for your Django project. I feel some opportunity to try advice from the book in real project. I will start from project layout: normally you have something like this: $ tree trancoder trancoder ├── audiotranscoder │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py └── trancoder ├── manage.py └── trancoder ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py But in the book authors suggest that it can be changed to something like this: $ tree transcoder transcoder … -
Django + Celery & Rabbit - part one
Hello, today post is first one in series about Celery in Django application and how to use it. What you gain after reading such series? How to integrate celery + rabbitmq in basic Django application. So what will be our basic application? It is planned to be web service where you can upload mp3 file and then have them transcoded into ogg, wav and ac3 files. I wanted to make easy and in the same time sophisticated project. Recently I started reading an excellent book called Two Scoops of Django: Best Practices for Django 1.8. The book is about what to do and what not to do for your Django project. I feel some opportunity to try advice from the book in real project. I will start from project layout: normally you have something like this: $ tree trancoder trancoder ├── audiotranscoder │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py └── trancoder ├── manage.py └── trancoder ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py But in the book authors suggest that it can be changed to something like this: $ tree transcoder transcoder … -
Django + Celery & Rabbit - part one
First part of series about Django application with Celery and RabbitMQ. -
Dutch django meetup (feb 2016) summaries
Dutch django meetup revival - Erik Romijn Sponsored by http://byte.nl, organized by the Dutch django association (django vereniging). The association was founded to organize the 2011 Django Europ conference. They're also behind the "django under the hood" conferences. They're also supporting django girls workshops and even Python Namibia 2015. If you want to become a member, mail bestuur@djangovereniging.nl If you want to help with future meetups, contact him! Migrating nu.nl to Django - Besma Mcharek-Boussif Besma works for Sanoma, the company behind http://www.nu.nl/, a very big news site in the Netherlands. The real title of the talk is "nu.nl performance and our journey in the django realm". She's a django backend developer. She's also a co-organizer of the django girls meetings. Nu.nl is the biggest Dutch news platform. 10^9 pageviews per day. They specialize on getting the news online fastest. Mobile and desktop web sites plus mobile apps (ios, android and windows) for tablets, phones and smart watches. There's now an ios team, an android team and a web/API and a CMS team. The API is also used by the mobile apps, btw. Regarding development: they try to use a devops mind set. It is almost continuous integration. About 10 … -
Django cookiecutter
Have you ever wanted to automate all these boring things that you have to do while setting up new django project? Like writing proper settings, setting up whole folder structure, adding docs, readmes, setup.py etc? There is app that can do these mundane actions for you: Cookiecutter Django. Q: What you get after reading this post? A: Basic understanding how you can automate boring tasks and get exciting ones done! Let's start with cookiecutter. What exactly is it? It's CLI tool for automatically generating projects from given template. What do I mean by that? Suppose that when you make new python project you want certain things to be setup the same way every time. For instance: setup.py or docs folders. Thanks to cookiecutter it's possible to automate these things so every time you make the new project the boring stuff is already made for you. Django Cookiecutter is made especially for django applications. Based on GitHub README it provides: For Django 1.9 Renders Django projects with 100% test coverage Twitter Bootstrap v4.0.0 - alpha End-to-end via Hitch AngularJS 12-Factor based settings via django-environ Optimized development and production settings Registration via django-allauth Comes with custom user model ready to go. Grunt … -
Django cookiecutter
Have you ever wanted to automate all these boring things that you have to do while setting up new django project? Like writing proper settings, setting up whole folder structure, adding docs, readmes, setup.py etc? There is app that can do these mundane actions for you: Cookiecutter Django. Q: What you get after reading this post? A: Basic understanding how you can automate boring tasks and get exciting ones done! Let's start with cookiecutter. What exactly is it? It's CLI tool for automatically generating projects from given template. What do I mean by that? Suppose that when you make new python project you want certain things to be setup the same way every time. For instance: setup.py or docs folders. Thanks to cookiecutter it's possible to automate these things so every time you make the new project the boring stuff is already made for you. Django Cookiecutter is made especially for django applications. Based on GitHub README it provides: For Django 1.9 Renders Django projects with 100% test coverage Twitter Bootstrap v4.0.0 - alpha End-to-end via Hitch AngularJS 12-Factor based settings via django-environ Optimized development and production settings Registration via django-allauth Comes with custom user model ready to go. Grunt … -
Django cookiecutter
Automate everything. -
Python 3 in 2016
My completely anecdotal view on the state of Python 3 in 2016. Based on my own recent experience, observations, and exchanges with other members of the Python community. -
Python 3 in 2016
My completely anecdotal view on the state of Python 3 in 2016. Based on my own recent experience, observations, and exchanges with other members of the Python community. -
Wagtail: 2 Steps for Adding Pages Outside of the CMS
My first Caktus project went live late in the summer of 2015. It's a community portal for users of an SMS-based product called RapidPro. The portal was built in the Wagtail CMS framework which has a lovely, intuitive admin interface and excellent documentation for developers and content editors. The code for our Wagtail-based project is all open sourced on GitHub. -
Django-minipub: a minimal publication control mixin
Django-minipub is a minimal publication control system for Django. I wrote this app in 2013/2014 and I've used it on several websites... However, I've never had the time to talk about it! Time to fix that oversight.