Using MongoDB in Django Application

In previous article we learned how to install Elasticsearch and Kibana and connect them together. In second part of the same article we used Elasticsearch in Django project.

Elasticsearch can be used with relational database or non-relational database. In those articles we used relational database MySQL.

In this article we will see how to use MongoDB in Django application.

I use PythonAnyWhere to host Django application quickly. Read here how to host your Django app on PythonAnyWhere for free.

Continue reading “Using MongoDB in Django Application”

Elastic Search with Kibana and Django – part 2

In previous part, we installed Elasticsearch and Kibana. Now we will create a Django project and will link the elastic search with the project.

Django Project:

You can follow the official Django tutorials to create and start a Django project.  Or you follow below steps. We will be following the official documentation, but only the necessary steps.

– Make sure python 3 is installed on your machine. Although not mandatory but it is recommended to use virtual environment.

Install Django. Setup a database. We will be using MySQL.

– Create a project.
$ django-admin startproject elasticsearchdjango

– Change directory to elasticsearch. Create a new app ‘poll’.
$ python manage.py startapp polls

– If you are using virtual environment than install the dependencies using pip install -r req.txt  file after saving below lines in req.txt  file.

– Create a model in polls/models.py file.

Continue reading “Elastic Search with Kibana and Django – part 2”

Difference between list and tuples in Python and more such comparisons

In this article we will see key differences between commonly used terms in python. For example difference between tuple and list, difference between range and xrange and so on.

List and Tuples:

List:
– are mutable i.e. we can add, extend or update a list.
– generally are homogeneous data structures.


Tuples:
– are immutable i.e. we can not update a tuple.
– generally are heterogeneous data structure.
– is a sequence where position have semantic value.
– are more like records, collection of fixed number of fields.

Continue reading “Difference between list and tuples in Python and more such comparisons”

Python Script 1: Convert ebooks from epub to mobi format

We are starting a series of python scripts which we may use in our daily life to automate mundane task and save some time.

This is the first article in this series. Recently I bought Amazon’s Ebook Reader, kindle paperwhite 3. I purchased few books from kindle store and downloaded most of the books in Epub format. Now kindle doesn’t support epub format. You need to convert them to either mobi or azw3 format.

Continue reading “Python Script 1: Convert ebooks from epub to mobi format”

How to use Google reCAPTCHA in Django

Using Google reCAPTCHA in Django forms is one of the best way to prevent login attack in your Django application. Although you may deploy other measures like blocking user after 3 unsuccessful attempts or blocking the IP address but I think reCAPTCHA is one of the most widely used method to stop bots from attacking your login/sign-in page.

In this article we will see how to use Google reCAPTCHA in Django forms.

Continue reading “How to use Google reCAPTCHA in Django”

How to share data between two systems using python simple HTTP server

Consider this, you want to share files between two system or you want to send really large file to your friend or you want to share new season of ‘The big bang theory’ among your peers. What if you do not have pen drive with you. What if file size is larger than pen drive capacity? What if you have some file which is required by 100 people.

Python Simple HTTP server comes to the rescue. Using a one line command in your terminal you can overcome all limitations discussed above.

Continue reading “How to share data between two systems using python simple HTTP server”

What is the meaning of different aphorism in zen of python

The Zen of Python is a collection of 20 software principles that influences the design of Python Programming Language.

Continue reading “What is the meaning of different aphorism in zen of python”