Skip to main content

Posts

Showing posts from February, 2018

Getting started with Django 1.11

Django is an open source web-framework written in Python, which is based on the Model-View-Controller (MVC) architectural pattern. It is mainly used for creation of database driven web-applications. Comon websites which uses Django are Instagram, Washington times, Mozilla etc. Let's get started by installing Django (I am using 1.11 at the time of writing this). pip install django Once the Django is installed, a new project is created using the django-admin command. Before we proceed further, I want to clarify that a Django   project is actually a collection of mutliple  applications. Now each application could be responsible for different tasks for a complete website. So, if you have a blog site, you can have one app for account management, one for managing comments. Advantage with this approach is that these apps are reusable in other projects. Other than applications, a Django project will also contain configuration files to manage that project including command

Django authentication using class based views

Django 1.11 has introduced Class-Based Views for Authentication. In this post, we'll look over how to use these class based views in our project. Let's start with the implementation of "Register User" functionality first. There is no pre-defined class based view for this. So, I'll use CreateView for achieving this task. Through out this post, I'll assume that we are using accounts app. Register User Functionaility :  Forms.py for user registration (accounts/forms.py) # Forms.py ( accounts app ) from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User class RegisterUserForm (UserCreationForm): class Meta : model = User fields = ( 'username' , 'first_name' , 'last_name' , 'email' , 'password1' , 'password2' , ) Views.py for

Secure your blog or site with HTTPS using free SSL certificate from Cloudflare

HTTPS is the secure version of HTTP protocol for commuincation between client and server. This type of communication requires a certificate from a trusted source which is used to establish a secure connection. Typically, most of the web-hosting companies like GoDaddy etc provides this paid service by verifying your identity. Cloudflare has introduced Universal free SSL certificates which you can use with custom domain from blogger, wordpress blog or any website. Just to add this free SSL certificate will require you to use Cloudflare DNS and this free certificate may not be supported on old browsers for which you will have to upgrade to their paid service. Setting up Cloudflare Account :- First thing that you have to do is to setup an account with Cloudflare in order to use their free SSL Visit Cloudflare website and signup for their free account. After signup, add your website and click on Scan DNS Records. It will take upto 1-2 minutes to scan your domain and retrieve the

GET vs POST in HTTP request

Hyper Text Transfer Protocol (HTTP) is an application protocol which is the backbone of world wide web. It works as request-response protocol for the client-server architectures. So your browser on computer, mobile will be a client and the system hosting the website that you are visiting will be a server. Now there are two common methods of communication between client and server - GET & POST. Communication could be you searching for something on Google, logging into your Facebook account. The GET Method :-  - In GET method, name-value pairs are passed with the URL itself, which means the parameters are visible in the browser address bar.  e.g.  www.example.com/find?name=test - Since the parameters are visible in the browser, GET based addresses can be bookmarked, so that the same websites (with desired arguments) can be visited again. - There are length restrictions on URL, so GET method can't be used for passing large data to the server. - Sensitive data

Indices and Slices in Python

In Python, indices and slicing is used very commonly for retrieving an individual item or range of items from list, string, tuples. In this post, I'll cover on the basics of indexing using strings. s= "0123456789" Syntax for using indexing/slicing is : [start:end:step] , where start, end and stop are optional. When using the slicing, start is the index from where to start printing and end is the first character which is NOT to be printed. Step decides the index increment value and if it is positive, then movement is done in forward direction. # Example 1 s[::] => will print 0 1 2 3 4 5 6 7 8 9 #In this case start will be 0 and stop will be len(s) and step will be 1. # Example 2 s[1:5:1] => will print 1 2 3 4 # Example 3 s[::-1] => will print 9 8 7 6 5 4 3 2 1 0 #In this case start will be -1 and end will be -len(s)-1. # Example 4 s[::-2] => will print 9 7 5 3 1