Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
PyCon tutorials, day one
11:39: This morning’s tutorial was on the OpenAPI specification, née Swagger. I wasn’t satisfied with this one. Much of it was a series of, “Look at X. Now make the changes in your file that are like X,” exercises. At times it was almost pattern-matching in nature. I wish it had spent more time delving under the covers. However, I extracted some useful nuggets of information. In previous jobs, my teams have used Django Rest Framework for the API implementation and django-rest-swagger to generate live documentation. Time-consuming, “now you have two problems,” issues were always encountered. Django Rest Framework is a framework in and of itself, and so it’s a framework wrapping another framework. Add in django-rest-swagger and you almost have three frameworks, with multiple points of impedance mismatch to each other. (This is understandable. It’s amazing it all works as well as it does.) The process of keeping it all happy took time, and the end results were problematic. In at least two instances, my team chose to lower the API’s quality in order to keep using DRF. One pain point was nested parameters; they (particularly modifiable ones) were extraordinarily painful. So, back to the tutorial. Coffee Meets Bagel’s … -
Using Python and Google Docs to Build Books
When I started my latest fiction book, The Darkest Autumn, I wrote out the chapters as individual files. I did it in a text editor (Sublime) and saved the files to a git repo. The names of the files determined their order, chapters being named in this pattern: the-darkest-autumn $ tree . ├── 01_Beginnings.md ├── 02_Town_of_Ravenna.md ├── 03_Walls_of_Ravenna.md As the book developed I thought about moving it to Scrivener. If you don't know, Scrivener is an excellent tool for writing. It encourages you to break up your work into chapters and scenes. The downside is that Scrivener is complex (I want to write, not figure out software) and Scrivener isn't designed for simultaneous collaboration. The latter issue is a very serious problem, as I like to have others review and comment on my writing as I go. What I really wanted to do is combine the chapter breaking of Scrivener with the simplicity and collaboration of Google Docs. Preferably, I would put the book chapters into Google Docs as individual files and then send invites to my editor, wife, and my beta readers. By using Google Docs I could ensure anyone could access the work without having to create a … -
Using Python and Google Docs to Build Books
When I started my latest fiction book, The Darkest Autumn, I wrote out the chapters as individual files. I did it in a text editor (Sublime) and saved the files to a git repo. The names of the files determined their order, chapters being named in this pattern: the-darkest-autumn $ tree . ├── 01_Beginnings.md ├── 02_Town_of_Ravenna.md ├── 03_Walls_of_Ravenna.md As the book developed I thought about moving it to Scrivener. If you don't know, Scrivener is an excellent tool for writing. It encourages you to break up your work into chapters and scenes. The downside is that Scrivener is complex (I want to write, not figure out software) and Scrivener isn't designed for simultaneous collaboration. The latter issue is a very serious problem, as I like to have others review and comment on my writing as I go. What I really wanted to do is combine the chapter breaking of Scrivener with the simplicity and collaboration of Google Docs. Preferably, I would put the book chapters into Google Docs as individual files and then send invites to my editor, wife, and my beta readers. By using Google Docs I could ensure anyone could access the work without having to create a … -
Runtime Permissions in Android: The What, Why, and How
It’s great if you are dealing with an application from a famous and well-known developer whom you can trust. But imagine that you want to install a music player that requires, let’s say, information about your location. It looks very suspicious, doesn’t it? The post Runtime Permissions in Android: The What, Why, and How appeared first on Distillery. -
Kubernetes Health Checks in Django
Kubernetes Health Checks in Django -
Django and nginx file proxy - part one
In this blog post series, I will show you how to use Nginx for hiding download urls. Django will serve us as a backend. Let's go! In this series I will build simple web application - user upload a file via api and then she/he wants to download it. But … -
Fastest Redis configuration for Django
I have an app that does a lot of Redis queries. It all runs in AWS with ElastiCache Redis. Due to the nature of the app, it stores really large hash tables in Redis. The application then depends on querying Redis for these. The question is; What is the best configuration possible for the fastest service possible? Note! Last month I wrote Fastest cache backend possible for Django which looked at comparing Redis against Memcache. Might be an interesting read too if you're not sold on Redis. Options All options are variations on the compressor, serializer and parser which are things you can override in django-redis. All have an effect on the performance. Even compression, for if the number of bytes between Redis and the application is smaller, then it should have better network throughput. Without further ado, here are the variations: CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": config('REDIS_LOCATION', 'redis://127.0.0.1:6379') + '/0', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } }, "json": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": config('REDIS_LOCATION', 'redis://127.0.0.1:6379') + '/1', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "SERIALIZER": "django_redis.serializers.json.JSONSerializer", } }, "ujson": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": config('REDIS_LOCATION', 'redis://127.0.0.1:6379') + '/2', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "SERIALIZER": "fastestcache.ujson_serializer.UJSONSerializer", } }, "msgpack": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": config('REDIS_LOCATION', … -
Distillery QA Team Makes the Finals in the 2nd Open EU Championship as They Prepare for the Grand Final in Poland
The Distillery Quality Assurance team competed in the 2nd Open European Championship for Web and Mobile Specialists and made it to the finals! Anna Varetsa, QA Manager, and Ekaterina Golubeva, QA Specialist, excelled at solving the different challenges presented by Jury Board, a selection of highly qualified and experienced industry professionals. The results were revealed on April 28th, after two weeks of nervously waiting for the outcome. The post Distillery QA Team Makes the Finals in the 2nd Open EU Championship as They Prepare for the Grand Final in Poland appeared first on Distillery. -
Django Version Viewer Announcement
Presenting a new open source plugin: The Django Version Viewer! Imaginary Landscape is pleased to present a helpful new plugin for the Django Web Framework - The Django Version Viewer! If you find yourself frequently switching between projects or perhaps looking at a codebase you haven’t seen in some time, it’s often useful to know the contents of the project’s virtual environment. Typically this information is only accessible either by examining your project’s requirements.txt (which may or may not accurately reflect what is installed in your environment) or by accessing your app’s server directly to examine the app’s virtual environment. The Django Version Viewer is a handy tool that exposes this information in a handful of ways: Through the Django Admin panel The plugin conveniently exposes a link at the top of your admin index pane to expose a simple drop down listing all of your project dependencies. Through a DjangoCMS Toolbar Menu Item If Django CMS is installed, a new menu item will be added to the CMS Toolbar Page Menu that will allow opening the version viewer popup. Through an API call Alternatively, you can make a request to a URL at www.yourAppsDomain/django_version_viewer to retrieve a list of … -
Django and working with large database tables
The slides from my presentation for the Django Stockholm Meetup group. Contains small comparison between MySQL and PostgreSQL in terms of performance when modigying the tables structure. Django and working with large database tables from Ilian Iliev -
A simple Python email gateway
Say you have a Django web application that you want to integrate with emails to make it possibile to send data and files to your web application over SMTP. The good news is that Python has a simple SMTP daemon in the standard library, together with modules to parse emails. Let’s see how to create a simple email gateway on top of these tools. Using the following Python module you can setup a simple pure Python email server on port 25, parse the incoming emails and make a multipart/form-data POST HTTP request to your web application. You’ll need the awesome Requests library for the HTTP request to work. In a production environment you can setup supervisor to launch your simple SMTP server. With a simple configuration like this: [program:smtp_server] command = /home/ubuntu/.virtualenvs/venv/bin/python /home/ubuntu/mail_gateway/smtp_server.py user = root Then try to send an email to your server, if the server public IP has been associated to a DNS record yourserver.example.com you can use something like test@yourserver.example.com as a recipient, and you should see the incoming email in the logs. Have fun with emails! -
A simple Python email gateway
Say you have a Django web application that you want to integrate with emails to make it possibile to send data and files to your web application over SMTP. The good news is that Python has a simple SMTP daemon in the standard library, together with modules to parse emails. Let’s see how to create a simple email gateway on top of these tools. Using the following Python module you can setup a simple pure Python email server on port 25, parse the incoming emails and make a multipart/form-data POST HTTP request to your web application. You’ll need the awesome Requests library for the HTTP request to work. https://gist.github.com/baxeico/d5d6f855774ba9f72e11909648a46cae In a production environment you can setup supervisor to launch your simple SMTP server. With a simple configuration like this: [program:smtp_server] command = /home/ubuntu/.virtualenvs/venv/bin/python /home/ubuntu/mail_gateway/smtp_server.py user = root Then try to send an email to your server, if the server public IP has been associated to a DNS record yourserver.example.com you can use something like test@yourserver.example.com as a recipient, and you should see the incoming email in the logs. Have fun with emails! The post A simple Python email gateway appeared first on Augusto Destrero - Freelance developer and sysadmin. -
A simple Python email gateway
Say you have a Django web application that you want to integrate with emails to make it possibile to send data and files to your web application over SMTP. The good news is that Python has a simple SMTP daemon in the standard library, together with modules to parse emails. Let’s see how to create a simple email gateway on top of these tools. Using the following Python module you can setup a simple pure Python email server on port 25, parse the incoming emails and make a multipart/form-data POST HTTP request to your web application. You’ll need the awesome Requests library for the HTTP request to work. import smtpd import asyncore import logging import email from email.header import decode_header import requests logger = logging.getLogger(__name__) class CustomSMTPServer(smtpd.SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data): try: logger.debug('Receiving message from: %s:%d' % peer) logger.debug('Message addressed from: %s' % mailfrom) logger.debug('Message addressed to: %s' % str(rcpttos)) msg = email.message_from_string(data) subject = '' for encoded_string, charset in decode_header(msg.get('Subject')): try: if charset is not None: subject += encoded_string.decode(charset) else: subject += encoded_string except: logger.exception('Error reading part of subject: %s charset %s' % (encoded_string, charset)) logger.debug('Subject: %s' % subject) text_parts = [] attachments = {} logger.debug('Headers: %s' … -
Django webpacker - A compression tool to bundles css, js files
In production, it's challenging to developers to improve the performance of an application. One of the technique to improve performance is compressing the CSS, js files into a single file. Django webpacker provides you a single compressed CSS, js file to the page. Instead of generating compressed files for every request in production, we're generating compressed css, js files, updates to html file in the development only. Django webpacker really helps you to generate these compressed files with webpack Django webpacker is a django compressor tool which bundles css, js files to a single css, js file with webpack and updates your html files with respective css, js file path with a single management command.. Django webpacker uses webpack, npm, aws s3 services to provide its features in an effective way. Webpack is a system for bundling the front-end assets of a web application into a few static resources that represent the bulk of the application's CSS, Javascript, and images. npm makes it easy for JavaScript developers to share the code that they've created to develop applications. With the help of packages(A reusable code) will generate compressed css , js files. Django webpacker also supports django-storages to load compressed static files from AWS … -
How to use nested formsets in django
Django Formsets manage the complexity of multiple copies of a form in a view. By using formsets you can know how many forms were their initially, which ones have been changed, and which ones should be deleted. Similar to Forms and Model Forms, Django offers Model Formsets, which simplify the task of creating a formset for a form that handles multiple instances of a model. Django also provides inline formsets which can be used to handle set of objects belong to common foreign key. In the below example models, we can write a inline-formset for handling all children for a parent or all addresses of a child. # models.py class Parent(models.Model): name = models.CharField(max_length=255) class Child(models.Model): parent = models.ForeignKey(Parent) name = models.CharField(max_length=255) class Address(models.Model): child = models.ForeignKey(Child) country = models.CharField(max_length=255) state = models.CharField(max_length=255) address = models.CharField(max_length=255) # forms.py from django.forms.models import inlineformset_factory ChildrenFormset = inlineformset_factory(models.Parent, models.Child, extra=1) AddressFormset = inlineformset_factory(models.Child, models.Address, extra=1) By using above formsets you can handle all children for a parent in one page and can handle all addresses of a child in other page. But if you want to allow the users to add/edit all children along with addresses, all in a single page, then … -
What's great about Django girls to inspire women into programming
Now a days programming is a hot topic across the globe. Django girls are inspiring more women into programming. Which is an international community to teach programming stuff and to getting more women into tech.They run free programming workshops all over the world and offering several opportunities for women to develop coding skills and to make the industry more balanced. It's important to encourage beginners/non-programmers that programming is not hard as they think. Where does it start? It started in 2014 by two women, Ola Sitarska and Ola Sendecka. Their main aim is to fall women into the programming world. Django girls workshops are free and till now they have conducted the events Over 67 countries around the world, where women can learn extensive programming stuff and they will get an awesome programming experience at the first time. It was not only a programming session but something as exciting. What They Do? They will guide all the participants to learn how to code using Django. They will start from the ground level. So, no one left behind. There are so many mentors & volunteers to guide everyone in each step. A participant can move as fast or as slow as … -
How to convert xml content into json using xmltodict
xmltodict is a python package which is used to convert XML data into JSON and vice versa. Within a less span of time, we can also process large amounts of data and get the desired results. Installation: pip install xmltodict It supports both python2.7, 3.4 versions Advantages over other packages: 1. No need to process each node in XML document to get the results 2. Easy to convert complex XML data into JSON 3. It's user-friendly Converting XML to a dictionary: >>> import xmltodict >>> import json >>> json.loads(json.dumps(xmltodict.parse(''' <root> <persons city="hyderabad"> <person name="abc"> <name age="50" mobile="789" /> </person> </persons> <persons city="vizag"> <username></username> <person name="xyz"> <name age="70" mobile="123" /> </person> </persons> </root> '''))) {u'root': {u'persons': [{u'@city': u'hyderabad', u'person': {u'@name': u'abc', u'name': {u'@mobile': u'789', u'@age': u'50'}}}, {u'@city': u'vizag', u'person': {u'@name': u'xyz', u'name': {u'@mobile': u'123', u'@age': u'70'}}}]}} Converting dictionary to XML: >>> xmltodict.unparse({u'root': {u'persons': [{u'@city': u'hyderabad', u'person': {u'@name': u'abc', … -
Django deployments without downtime
This post describes a deployment and maintenance method for Django projects that was designed with scalability in mind. The goal is to push new releases into production at any moment with minimal or no downtime. Upgrades can be performed with unprivileged access to the production server, and rollbacks are possible. I use Gunicorn, Fabric and Supervisord in the examples. -
Stable Django deployments without downtime
This post describes a deployment and maintenance method for Django projects that was designed with scalability in mind. The goal is to push new releases into production at any moment with minimal or no downtime. Upgrades can be performed with unprivileged access to the production server, and rollbacks are possible. I use Gunicorn, Fabric and Supervisord in the examples. -
Machine learning empowered blackkiwi
A blackkiwi which tells your mood. Blackkiwi is a django powered website which uses machine learning to tell if you wrote happy or sad things on your latest Facebook status. And it tends to be wayyy positive. But we will get there… The genesis of blackkiwi There were two main things combined with the genesis of blackkiwi. The first it was this curiosity about Natural Text processing and classificaiton techniques. In particular I wanted to write some classifers to see how well they were performing and I also wanted to try to do and test something new. But I needed some kind of application. This is usually a good trick in programming in general. If you build towards something, it is always easier to stay motivated and actually getting it done, instead of giving up the hobby and end up playing World of tanks on the play :). The second ingredient was to try to test the release process via gitlab, using automatic push via CI to a server. As stack I wanted to use a classic dokku stack which I’m very happy to use, beccause it basically brings the nice and easy way to deploy similar to heroku/gondor style … -
Django REST framework (DRF) with Angular 2+ tutorial (Part 1)
This is the first part of a tutorial series about getting started with Django framework and Angular 2 . The final objective is to create a restful web application which has two separate parts .The first part is the back end which is created with Django and the Django REST framework ,the second part is the front end which is built using Angular 2+ framework . Django REST framework (DRF) with Angular 2+ tutorial (Part 1) Django REST framework (DRF) with Angular 2+ tutorial (Part 2) Django REST framework (DRF) with Angular 2+ tutorial (Part 3) We are going to use Django 1.11 ,Django REST framework 3.6.2 and Angular 2+ . Before starting ,this tutorial has a bunch of development requirements : You need to have Python installed and configured PIP and Virtualenv installed Node.js and Angular 2 CLI installed Objectives of the part 1 In the first part of these tutorial series ,we are going to cover basic introductions to the two server side used frameworks Django and DRF ,and their initial setup . Getting started with Django and DRF . The custom project anatomy and structure (front end and back end) Getting started with Django and DRF Django … -
Django REST framework (DRF) and Angular 2 tutorial (Part 1)
This is the first part of a tutorial series about getting started with Django framework and Angular 2 . The final objective is to create a restful web application which has two separate parts .The first part is the back end which is created with Django and the Django REST framework ,the second part is the front end which is built using Angular 2 framework . We are going to use Django 1.11 ,Django REST framework 3.6.2 and Angular 2 . Before starting ,this tutorial has a bunch of development requirements : You need to have Python installed and configured PIP and Virtualenv installed Node.js and Angular 2 CLI installed Objectives of the part 1 In the first part of these tutorial series ,we are going to cover basic introductions to the two server side used frameworks Django and DRF ,and their initial setup . Getting started with Django and DRF . The custom project anatomy and structure (front end and back end) Getting started with Django and DRF Django is a web framework based on Python which allows developers to quickly prototype and build web applications .It has a powerful ORM that abstracts how you can interact with popular … -
Make More Room: How to Resolve Database Record Limitations
Sometimes in the process of designing a database, developers can underestimate the scope of a project. If that project were to become successful, it would result in significant loads and put undue strain on the system and it’s developers down the line. Eventually, people realize that they are using an INT identity key with a maximum value of 2,147,483,647 as the primary key of a huge table. The post Make More Room: How to Resolve Database Record Limitations appeared first on Distillery. -
How To Write Custom migrations in Django
Migrations are mainly for keeping the data model of your database up-to-date. Django will never run same migration file more than once on the same database. All this is managed by table named "django_migrations" which gets created when we first apply the migrations. For each migration(file), a new record(row) is inserted into this table. There are also a few “special” operations of Migration class which can be used to add our custom migrations. RunSQL This allows us to execute raw SQL. Example: from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ... dependencies goes here ] operations = [ migrations.RunSQL("INSERT INTO product (title) VALUES ('Product1');"), ] RunPython This can be used to run custom Python code. Here code should be separate function that accepts two arguments - first is an instance of django.apps.registry.Apps containing historical models that match the operation’s place in the project history, and the second is an instance of SchemaEditor. Example: from __future__ import unicode_literals from django.db import migrations def create_countires(apps, schema_editor): Country = apps.get_model("app_name", "Country") Country.objects.bulk_create([ Country(name="India"), Country(name="USA"), ]) class Migration(migrations.Migration): dependencies = [ ... dependencies goes here ] operations = [ migrations.RunPython(create_countires), ] Once we have the function we can … -
Django efficient implementation of Amazon s3 and Cloufront CDN for faster loading.
Django by default to store the files in your local file system. To make your files load quickly and secure we need to go for any third party storage systems. AWS s3 is one of the storage service for the Internet. It is designed to make web-scale computing easier for developers. django has a package called django-storages which can be used to store the files in the amazon s3. and serve them from its cloud front service. Implementing django-storages with amazon s3 as storage service in your django application: To implment django-storages in your django application you need to follow the following steps. 1. Install django-storages: We can install django-storages with the following command. pip install django-storages 2. Keep storages in your installed apps. INSTALLED_APPS = ( ... 'storages', ... ) 3. Change your DEFAULT_FILE_STORAGE setting in your settings.py file: Django by default comes with a setting called DEFAULT_FILE_STORAGE which deals with file storage. By default its value is 'django.core.files.storage.FileSystemStorage'. By keeping this value to DEFAULT_FILE_STORAGE, django, by default tries to store the files on your local machine. To store your files in amazon s3 just change that value to 'storages.backends.s3boto3.S3Boto3Storage' DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' 4. Configure your AWS ACCESS_KEY …