Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Deploying Your Django app on Heroku
Heroku is a cloud application platform it's a new way of building and deploying web apps, Which makes easy to host your application in the cloud with a simple git push command. Heroku supports several programming languages like(Python, Java, PHP) Install the Heroku Toolbelt: The first thing you need to do is to install the Heroku toolbelt. In order to interact with heroku service, the toolbelt is best command line software. Here you can find out the Heroku toolbelt installation for Debian/Ubuntu, Run this from your terminal: wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh In the below link you need to select your required operating system(Download Heroku Toolbelt for..) for installing heroku toolbelt in your system. And then you can proceed to install. Please click here to install Heroku ToolBelt After successfully installation of toolbelt, you can use the heroku command from your terminal. heroku login You will prompt to provide heroku credentials(Email and password), once you have authenticated you can access both heroku and git commands. Create your heroku app: The following command is used to create an app heroku create your-app-name Here 'your-app-name' should be unique, heroku will generate default app-name if you won't specify any app-name. For creating remote … -
Django Unit Test cases with Forms and Views
Test Cases For Forms, Views In this post, we’ll see how to write unit test cases for any project. Having tests for any project will helps you to find bugs. If any of the function breaks, you will know about it. Its easier to debug code line by line. Unit Tests: Unit Tests are isolated tests that test one specific function. Test Case: A test case is executing set of features for your Application. Proper development of test cases finds problems in your functionality of an Application. Test suite: A test suite is a collection of test cases. It is used to aggregate tests that should be executed together. In general, tests result in either a Success (expected results), Failure (unexpected results), or an error. While writting test cases, not only testing for the expected results but also need to test how good your code handles for unexpected results. Testing the Forms: Consider a Form: from django import forms from .models import * class UserForm(forms.ModelForm): class Meta: model = User fields = ('email', 'password', 'first_name', 'phone') setUp(): The setUp() methods allows to define instructions which will be executed before and after … -
Angular 2 Setup Guide
# This guide is still being de... -
Srvup 2 is here
The future of education will l... -
Typescript Setup Guide
** This guide is still being d... -
How To Export Django Model Data Along With Its Parent Model Data via dumpdata Command
Django dumpdata command lets us export model objects as fixtures and store them in json / xml formats. All is good and works fine until a moment when your model is a children of a concrete model and shares two db tables (one for parent another is for model). If you ... Read now -
Activate, Reactivate, Deactivate your Virtualenv
Here's a quick guide to activa... -
Django PositionField
Sometimes you need ordering in... -
5 Reasons to Use Class Based Views
Anytime anyone brings up Class Based Views, generic and otherwise, it is similar to the Vim vs Emacs debate. So lets pile on a bit more. But not really. In actuality, I feel like there are good, solid, and legitimate reasons to use Class Based Views which get passed over in the middle of arguments. In this weeks topic I talk about 5 of those reasons I think people should use Class Based Views. In reality there are more, but I wanted to keep the video short'ish. 5 Reasons to Use Class Based Views -
How to Implement Case-Insensitive Username
Inspired by a discussion in the How to Extend Django User Model comments, I decided to compile a few options on how to implement a case insensitive authentication using the built in Django User. Thanks to Paul Spiteri for bringing up the question and also to provide a possible solution! Option 1: Custom Authentication Backend Please note that there is a small difference in the implementation between Django 1.10 and 1.11, as from 1.11 the authenticate method receives a request object. Django Version 1.10.x Or Below If your application is already up and running and you can’t afford to customize the Django User model, this is the less intrusive way. Create a python module named backends.py anywhere in your project and add the following snippet: backends.py from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend class CaseInsensitiveModelBackend(ModelBackend): def authenticate(self, username=None, password=None, **kwargs): UserModel = get_user_model() if username is None: username = kwargs.get(UserModel.USERNAME_FIELD) try: case_insensitive_username_field = '{}__iexact'.format(UserModel.USERNAME_FIELD) user = UserModel._default_manager.get(**{case_insensitive_username_field: username}) except UserModel.DoesNotExist: # Run the default password hasher once to reduce the timing # difference between an existing and a non-existing user (#20760). UserModel().set_password(password) else: if user.check_password(password) and self.user_can_authenticate(user): return user Now switch the authentication backend in the settings.py module: settings.py … -
Django Dynamic Formsets
Django forms are one of the most important parts of the stack: they enable us to write declarative code that will validate user input, and ensure we protect ourselves from malicious input. Formsets are an extension of this: they deal with a set of homogeous forms, and will ensure that all of the forms are valid independently (and possibly do some inter-form validation, but that's a topic for a later day). The Django Admin contains an implementation of a dynamic formset: that is, it handles adding and removing forms from a formset, and maintains the management for accordingly. This post details an alternative implementation. *** A Formset contains a Form (and has zero or more instances of that Form). It also contains a "Management Form", which has metadata about the formset: the number of instances of the form that were provided initially, the number that were submitted by the user, and the maximum number of forms that should be accepted. A Formset has a "prefix", which is prepended to each element within the management form: {% highlight html %} {% endhighlight %} Each Form within the Formset uses the prefix, plus it's index within the list of forms. For instance, … -
News items from the new year
The last few months have been mostly occupied with fixing bugs and straightening out usage quirks as more and more people take Evennia through its paces.Webclient progressOne of our contributors, mewser/titeuf87 has put in work on implementing part of our roadmap for the webclient. In the first merged batch, the client now has an option window for adjusting and saving settings. This is an important first step towards expanding the client's functionality. Other features is showing help in an (optional) popup window and to report window activity by popup and/or sound. The goal for the future is to allow the user or developer to split the client window into panes to which they can then direct various output from the server as they please It's early days still but some of the example designs being discussed can be found in the wiki webclient brainstorm (see the title image of this blog for one of the mockups). New server stuffLast year saw the death of our old demo server on horizondark.com, luckily the new one at silvren.com has worked out fine with no hickups. As part of setting that up, we also got together a more proper list of recommended … -
A Unique Slug Generator for Django
Using the [Random String Gener... -
Random String Generator in Python
Sometimes you need a random st... -
How reliable is my virtual server?
Digital Ocean advertises its services as “cloud computing”, and sometimes refers to its virtual servers, its “droplets” that is, as “cloud servers”. Reader Chris Pantazis asked me if this means it has less downtime than a provider that doesn’t advertise them in this way. The answer is that “cloud” doesn’t mean anything at all. In this post I explain how virtual server providers minimize downtime. I assume you understand clearly what a “virtual machine” is. If you don’t, download VirtualBox on your computer, create a virtual machine, and run it; the best way to grasp the concept is to see it in action. We often use virtual machines as servers, in which case we also call them virtual servers. Virtual machines run inside physical machines. Depending on the capacity (mostly the RAM and CPU) of the physical machine and the size of the virtual machines, a physical machine can run from a handful to a few hundreds of virtual machines. Virtual machine providers like Digital Ocean have many computers stacked on a rack like the one on the picture on the right, and a data centre has many racks, as seen in the picture on the left. The virtual machine … -
Django Conditional Expressions in Queries
Django Conditional Expressions are added in Django 1.8. By using Conditional Expressions we can use "If...Elif...Else" expressions while querying the database. Conditional expressions executes series of conditions while querying the database, It checks the condition for every record of the table in database and returns the matching results. Conditional expressions can be nested and also can be combined. The following are the Conditional Expressions in Django and Consider the below model for sample queries class Employee(models.Model): ACCOUNT_TYPE_CHOICES = ( ("REGULAR", 'Regular'), ("GOLD", 'Gold'), ("PLATINUM", 'Platinum'), ) name = models.CharField(max_length=50) joined_on = models.DateField() salary = models.DecimalField() account_type = models.CharField( max_length=10, choices=ACCOUNT_TYPE_CHOICES, default="REGULAR", ) 1. WHEN A When() object is used as a condition inside the query from django.db.models import When, F, Q >>> When(field_name1_on__gt=date(2014, 1, 1), then="field_name2") # if we want the value in the field >>> When(field_name1_on__gt=date(2014, 1, 1), then=5) # we can specify external value in place of "5" >>> When(Q(name__startswith="John") | Q(name__startswith="Paul"), then="name") # we can also use nested lookups 2.CASE A Case() expression is like the if ... elif ... else statement in Python. It executes the conditions one by one until one of the given conditions are satisfied. If no conditions are satisfied then the … -
Caktus at PyCaribbean
For the first time, Caktus will be gold sponsors at PyCaribbean February 18-19th in Bayamon, Puerto Rico. We’re pleased to announce two speakers from our team. -
Local Domain & Subdomain Testing in Mac & Linux
What to do when you want to te... -
How to Vett Django Apps
There are a lot of 3rd party django apps that people put out which makes our lives easier, but are they good? There are a lot of ways to evaluate them, mostly it seems a lot of people use intuition. In this weeks video I go over several ways of how I go about vetting projects before use in my projects. How to Vett Django Apps -
Asynchronous Tasks Setup using Django, Celery and rabbitMQ
In this post, I’ll be talking about setting up a distributed task processing system for doing asynchronous processing. As your website grows and handles lot of traffic, there naturally comes a need to ensure best performance for your users. While there are multiple things which need to be done to achieve that, one of the most important things is processing things in background. One of the common example is sending an email to the user. Instead of sending the email synchronously and making the user wait till it completes, a better way is to put this email into a queue to be processed in background and let the user continue with other actions. Email is just an example, there are tons of other things which can be moved to background processing to give seamless experience to the user. Also if you are getting too many requests, your server might be busy in processing them one by one and lot of users have to wait for the request to be served if you are doing everything synchronously. The background processing comes as an effective way to solve this. In this post, we will learn to setup this system using Django, Celery, … -
Refactoring Django With Full Syntax Tree
Django developers decided to drop Python 2 compatability in Django 2.0. There are serveral things that should be refactored/removed. For example, in Python 2, programmers has to explicitly specify the class & instance when invoking super. class Foo: def __init__(self): super(Foo, self).__init__() In Python 3, super can be invoked without arguments and it will choose right class & instance automatically. class Foo: def __init__(self): super().__init__() For this refactoring, a simple sed search/replace should suffice. But, there are several hacks in codebase where super calls the grandparent instead of the parent. So, sed won't work in such cases. It is hard to refactor them manually and much harder for reviewers as there are 1364 super calls in code base. → grep -rI "super(" | wc -l 1364 So changes has to be scripted. A simple python script to replace super calls by class names will fail to capture classes with on top of them, classes with decorators and nested classes. To handle all these cases, this python script gets more complicated and there is no guarantee that it can handle all edge cases. So, a better choice is to use syntax trees. Python has ast module to convert code to AST … -
Provisioning django application using ansible
As I recently have opportunity of having a workshop about ansible in my work and I decided to write a blog post on how to provision django application using this tool. In this blog post I am using the same application as in puppet post. Table of Contents: What is ansible and how's is different from puppet Provisioning django application using ansible My thoughts and feelings about ansible What is ansible and how's is different from puppet Ansible is a tool that helps automate boring tasks. These tasks are connected with setting up Linux machines, installing proper software on them and moving code from repositories to machines. Ansible has a different way of accomplishing these tasks than puppet. It is using push system - in short ansible connects to your machine via ssh and push changes. No need for masters and agents etc. Puppet, on the other hand, is using pull system which allows every machine to pull changes from master. Ansible is using the same principles as puppet so you declare how should host look like after running ansible. Provisioning django application using ansible I will be provisioning geodjango-leaflet. I assume that you know basic concepts of ansible like … -
Provisioning django application using ansible
As I recently have opportunity of having a workshop about ansible in my work and I decided to write a blog post on how to provision django application using this tool. In this blog post I am using the same application as in puppet post. Table of Contents: What is … -
Introducing Ask
What is it? A community-pow... -
Introduction to API development using Django REST framework with Example
Django REST framework is a best toolkit to create an API It supports both ORM and Non-ORM data sources. It can support regular function based view and class based views. 1) Installation of Django REST framework. pip install djangorestframework 2) Add 'rest_framework' in 'INSTALLED_APPS' settings.py INSTALLED_APPS = ( ... 'rest_framework', ... ) 3) configure the Django REST framework with 'REST_FRAMEWORK' This framework already contains some default configurations though we can override them like below settings.py REST_FRAMEWORK = { .... 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ), .... } Now, we are ready to use the Django REST framework. It is very similar to the Django. Now create your app and add it to INSTALLED_APPS in settings.py. consider the below code for example. we are writing both function and class based views. You can use function based or class based based on your comfort. models.py from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin GENDER_CHOICES = ( ('Male', 'Male'), ('Female', 'Female'), ('Other', 'Other') ) class User(AbstractBaseUser, PermissionsMixin): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) email = models.EmailField(unique=True) username = models.CharField(max_length=100, blank=True, null=True) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) dob = models.DateField(null=True) phone = models.CharField(max_length=20, null=True) gender = models.CharField(choices=GENDER_CHOICES, max_length=6) address = models.TextField() password = models.CharField(maxlength=255) def …