Let's build it

Posted on Sun 04 March 2018 in project • Tagged with side-project, django, pythonLeave a comment


unsplash-logoJames Pond


After many years of developing web applications, I found my passion is building Web APIs. so why I like it, I like it because I think it's giving your application a power to integrate with other apps (desktop, mobile apps, etc.), other devices (Amazon Dot, Google Home, etc.), sensors (RaspberryPi, Arduino, etc.), and bots (Slack, Telegram, Facebook Messanger, etc.). Can you feel the power that Web API that can add to your apps?

Let's build something

After I found my passion and start to search for a project to ably what I like and keep developing it. I found that there is no Web API for Quran Tafseer/Translation. What can Quran Tafseer API do for developers? If you want to develop an application for Quran and you want to provide a Tafseer/Translation to the application users, you need to gather the information from more than one source. I found most of the existing applications done it and after that work, app developers will keep this information available to their app only, so I thought of doing this work for the community and provide Tafseer/Translation for free as Web API.


Stage I

I …

Continue reading

Create Login Page for your Django app

Posted on Tue 09 May 2017 in Django • Tagged with django, python, formsLeave a comment

Create Login Page for your Django app

Why Another Post about this?

I found each time I start new Django project, I need to create Login HTML page, and with that I need to write Django View and Form. Each time I tried to Google how to do it, I found many posts about how to do it from scratch, yep as you read, posts telling you how to build a Django View and Form for login page. And there are already built-in Django login View and Form (please check links). So I decided to write my own recipe on how to create Login page in your Django app using the built-in view and form to save time and stop reinvent the wheel.

How to do it?

Actually it’s an easy one, because we’ll use already built-in View and Form, so we will build the Template for it, that it. We have a Form and View ready, so first thing first, we’ll write a template to show HTML form for login, I'm assuming you have another template called base.html and we’ll just write the container block part only, and we are using Boostrap framework and crispy_form app.


{% extends "base.html …
Continue reading

Custom Client Side Validation for Parsley in Django

Posted on Sun 16 April 2017 in Django • Tagged with django, python, parsley, validationLeave a comment

Custom Validation for Parsley in Django

I wrote a post on how to add client side validation for Django Forms. In this post I’ll show you how to add custom client validation to Django Forms. I mean by custom validation is a validation that isn't available in django-parsley, like username availability, password strength, email duplication, etc.. let’s see how to add custom client side validation to Django Form.

Parsley remote validation

Parsley library has remote validation, it's calling AJAX service (Django view) and check if AJAX call returns 2xx HTTP status codes then it's valid input else it's invalid input and shows error message. Thankfully you can use remote validation in Django Form using django-parsley via parsley-extras attribute.


class UserRegistrationForm(forms.ModelForm):
    class Meta:
        parsley_extras = {
            'password': {
                'remote': reverse_lazy('validate-password-parsley'),
                'remote-message': "Password is invalid"
            'username': {
                'remote': reverse_lazy('validate_username_uniqueness'),
                'remote-message': "User with this username is already exists."
            'email': {
                'remote': reverse_lazy('validate_email_uniqueness'),
                'remote-message': "User with this email is already exists."

In the code above we are adding client custom validation as remote to password, username, and email fields, Did you notice that remote key is holding a URL to Django View? let’s create a complete sample to get our head around it.

Django Password …

Continue reading

Client side validation for Django Forms

Posted on Wed 08 March 2017 in Django • Tagged with Django, FormsLeave a comment



In DUTH 2016 there was a session for Django Validation by Loïc Bistuer, in the session Loïc showed many areas you can validate user inputs from Django Form way to the Database Engine. To be honest validation in Django is a piece of cake and even if there is special validation rules you want to implement, you can still implement it, as I said it is easy and straight forward in Django, all of these validation is server side which happen on web server not on client-side, so what about client side?

What is client side validation?

In simple way, client side validation is validation user input on browser before sending the data to sever.

It is good practice to validate user inputs from client side to save roundtrips to server, but it needs extra work to implement your validations using JavaScript or using HTML5 form validation, but there is a way to replicate Django form validation to client side, let’s see how.

Django Parsley

Django Parsley is a Django app that replicate Django Form validation to client side using ParsleyJS library, and it’s so easy to use it.

How to use Django Parsley?

  • Install Django Parsley …

Continue reading

Django is boring but you can contribute

Posted on Sun 08 January 2017 in Community • Tagged with community, Django, duthLeave a comment

Bored employee in front of computer

I attended Django Under The Hood 2016, in sprints there is a comment passing around which Django is boring. Django is boring is actually a good news for the framework users, but it's sad one for developers want to contribute to the framework.

Every time I go to check Django tickets to contribute, I found they are difficult and in depth, because Django is a mature project now and the amount of contribution needed to the codebase is rare, but if you want to contribute you can check easy pickings tickets. In DUTH before the sprints projects leaders start to ask attendees for contributions, I found this is a good opportunity for me and for anyone wants to help the community and start to contribute to Django community.

Github duth contributions

If you want to contribute to Django and help the community, I have some suggestions for you:

  1. Write blog posts on How-tos, tips, and tutorials for Django, and Django packages for example Django REST Framework.
  2. Help Django team to move the ticket from stage to another.
  3. Contribute to one of Django’s packages, specially packages you are using, check their github page and help them.
  4. Tried more than one package for X …
Continue reading

Yet another and easier way to daemonize Celery

Posted on Mon 21 November 2016 in Django • Tagged with django, python, celeryLeave a comment

I wrote a post about how to run celery as daemon and it has many steps to do, many files to copy to your server, configure permissions, and configure upstart, but after sometime I found another and easier way to daemonize Celery.

In this method we will use supervisor to daemonize Celery, and this can be achieved by 3 simple steps, so let's do it.

Step 1

Install Supervisord sudo apt-get install supervisor on Ubuntu server. For other OSs please visit the official documentation

Step 2

This is the most important step, and in this step we will create supervisor configuration file to daemonize Celery.

Supervisor Configuration File

Celery project provide the basic configuration file in their Github repository.

Supervisor configuration files live in \etc\supervisor\conf\

Celery official configuration file

; ==================================
;  celery worker supervisor example
; ==================================

; Set full path to celery program if using virtualenv
command=celery worker -A proj --loglevel=INFO


; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs …
Continue reading

Add isort and flake8 test to your Django Project

Posted on Tue 27 September 2016 in Django • Tagged with django, python, unittest, howtoLeave a comment

Unit Test Works

In this post I'll tell you how to add isort and flake8 tests to your Django project test suite, this is simple script and you can start from this point and customize you own test suite.

As they said Django is a “batteries included” web application framework, and one of the batteries is Testing framework, testing in Django is easy and you can start writing tests even if you didn't do it before.

If you ever work with Django, you will write tests for your project, to test your views, models, forms, etc.. but it's better if you can add isort and flake8 tests to maintain the quality of your Python code.


We need some packages first so we can run the tests

pip install flake8 isort flake8-isort


It's better to create and use sperate virtualenv


flake8-isort is using .isort.cfg file to run the isort test against it, so let's add our configuration file.

.isort.cfg file

max_line_length = 120
indent_style = space
indent_size = 4
known_first_party = isort
ignore_frosted_errors = E103
skip = runtests.py,build,.tox
balanced_wrapping = true
not_skip = __init__.py

Test Python Script

Now it's time to write the Python script to run Django, isort, & flake8 tests.

runtests …

Continue reading

How to run Celery as daemon?

Posted on Tue 20 September 2016 in Django • Tagged with django, python, celeryLeave a comment

celery smoothy

Install upstart script


We need to make the user which will be used to run celery an owner of log and run directories.

sudo chown -R root:root /var/log/celery/
sudo chown -R root:root /var/run/celery/

Celery upstart

1- Download celeryd file from Celery official github repository.

2- Copy celeryd to /etc/init.d/celeryd

sudo cp celeryd /etc/init.d/

3- Make it executable

sudo chmod +x celeryd

4- Make it run on startup

sudo update-rc.d celeryd defaults
sudo update-rc.d celeryd enable

5- make it owned by root

sudo chown root:root celeryd

6- Done, now you can start/stop/restart celeryd as service

sudo service celeryd start
sudo service celeryd stop
sudo service celeryd restart

Celerybeat upstart

1- Download celerybeat file from Celery official github repository.

2- Copy celerybeat to /etc/init.d/celerybeat

sudo cp celerybeat /etc/init.d/

3- Make it executable sudo chmod +x celerybeat

4- Make it run on startup

sudo update-rc.d celerybeat defaults
sudo update-rc.d celerybeat enable

5- make it owned by root

sudo chown root:root celerybeat

6- Done, now you can start/stop/restart celerd as service

sudo service celerybeat start
sudo service …
Continue reading

DjangoCon Europe 2016, me, and Django Sprints

Posted on Wed 07 September 2016 in Community • Tagged with community, Django, DjangoConLeave a comment

djangocon logo

djangocon name tag

Late in 2014 I decided to shift my development stack from Microsoft .NET Framework to Django/Python stack. It's been almost 2 years now and I'm really enjoying and learning many things. I'm so happy that I've done this leap. In 2016 I had the change to attend DjangoCon Europe 2016 at Budapest, Hungry. I enjoyed it to the maximum, it's my first time to meet the community, and it's first time attending one of Django community events.

Django Community

When I started to learn Django, I found everyone is recommending Django documentation itself as start, from my past experience in .NET framework that its documentation is not enough to get your head around the framework, you need at least to read one book or watch one video course, but after reading Django official documentation, I was shocked that it's enough as start, it's enough for your daily tasks, it's enough to dive in Django framework, or fixing issues. The quality of Django official documentation is amazing.

When I went to DjangoCon Europe 2016 I saw people reflecting the philosophy of Django framework, the community is so welcoming as Django documentation, I had the chance to meet Russell Keith-Magee and …

Continue reading

PACKT publishing ebooks and videos 50% discount offer

Posted on Wed 17 February 2016 in Python • Tagged with django, python, ebooksLeave a comment

Generously PACKT publishing is offering 50% discount on Python and Django ebook and videos. PACKT has many Python ebooks and videos from novice to advanced level, it one of the most publishing company that releases books and videos for Python and Django, If you tried to Google a book for Python or Django, you differently will find one of their books in the search results.

Interesting ebooks and videos for Python:

Python Machine Learning

Mastering Python

Python DAta Analysis

Geospatial Development by Example Python

Interesting ebooks and videos for Django:

Web Development Django Cookbook

Django By Example

Master Django Web Developement


Please take the chance and buy your favorite Python or Django ebooks or videos form PACKT publishing. This offer is valid till 28th of March 2016 so please hurry up

  • For Python books and videos use PYTHON50 code.
  • For Django books and videos use DJANGO50 code.
Continue reading