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”

List of USA states in Python-Django format

In one of previous article we released the list of Indian states in different formats (CSV, List, Set, Model Choice, HTMLSelect) to be used in python-django project. We received few requests to release the USA states in same format. So here we are, presenting to you the states of USA in different Python-Django format.

Continue reading “List of USA states in Python-Django format”

List of Indian States in Python Format

So I was working on a project where I needed list of Indian States in Python format. I looked around on the web but the data was not available in required format. So I decided to create the list of Indian states in different formats which can be used directly in Python-Django project.

You can simply copy paste the data in any of the below format.

Continue reading “List of Indian States in Python Format”

How to send bulk emails for free using Mailgun and Python Django

Consider these scenario in your newly developed Django Application:

  • You need to send promotional emails to all the registered users.
  • You need to send email confirmation link or password reset link.
  • You need to send weekly newsletter to you readers.

What do you choose? Free Gmail Account to send email using python code? That is a nice idea provided you want to look unprofessional and you need not to send more than 500 emails per day.

But if you want professional look in your emails [from address something like admin@yourwebsite.com  instead of something@gmail.com  and do not want the limit on per day email count, then this article is for you.

Continue reading “How to send bulk emails for free using Mailgun and Python Django”

How to schedule a cron on pythonanywhere server

If you have hosted your Django app on pythonanywhere.com server and you want to schedule a cron job on the server to execute some task periodically ( daily or hourly) then this article is for you.

cron jobs are executed after a fixed interval of time, repetitively until stopped explicitly. This may come handy if you want to send bulk mails every hour or you may want to take a backup of your database or basically anything you want to perform periodically.

Continue reading “How to schedule a cron on pythonanywhere server”

How to start logging errors in Django app

In development or testing environment, you may set DEBUG=True  in your settings.py  file and whenever any error is thrown, you see it in the browser.

Setting DEBUG=True  in production environment is not recommended. Debug should be set to False on live servers so that stack trace is not visible in case of any error. Hackers or malicious users may exploit this and may attack you web application.

So how do you debug you application on live servers? Answer is Logging the errors in log files.

Lets  see how to start logging errors in django?

Continue reading “How to start logging errors in Django app”

Designing custom 404 and 500 error pages in Django

It happens very frequently that a visitor on your website typed a wrong URL or the page user is looking for no longer exists. What do you do to handle such cases.

You have three options.

  • Redirect the visitor to home page, silently.
  • Show a boring 404 page and then ask them to click on a link.
  • Create your own funny/awesome/informative custom 404 error page.

In this article we will discuss the third option.

Continue reading “Designing custom 404 and 500 error pages in Django”