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”
In previous part, we installed Elasticsearch and Kibana. Now we will create a Django project and will link the elastic search with the 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
– Create a model in polls/models.py file.
from django.db import models
author = models.CharField(max_length=100)
question_text = models.CharField(max_length=1000)
pub_date = models.DateTimeField('date published')
Continue reading “Elastic Search with Kibana and Django – part 2”
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:
– are mutable i.e. we can add, extend or update a list.
– generally are homogeneous data structures.
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
– 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”
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”
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”
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”
The Zen of Python is a collection of 20 software principles that influences the design of Python Programming Language.
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Continue reading “What is the meaning of different aphorism in zen of python”
To send email using python script via Office 365, use below code. This code is tried and tested.
Continue reading “How to send email from Python and Django using Office 365”