Django-Web Application

Django is a popular application framework used by web developers. It is mainly used by Python developers who want to have a web application. Since in python if one doesn’t use a framework then the application would be a series of scripts. And the scripts have to be executed in a shell.

If nothing specific is done on the application it would just run locally within your computer only. So if one has to broadcast his/her application to the outside world it has to be embedded in a framework.

Most of the frameworks nowadays follow the MVC Architecture also known as Model View Controller. Apart from Django the other frameworks which follow this architecture are Spring, AngularJS and many other frameworks.

So in order to build web applications nowadays it would be always good to get the basics of MVC architecture. There are a countless number of tutorials in the net which would help you get a basic understanding of MVC Architecture.

Running a Python script on a web server

Python is a great language to write scripts. Sometimes if we need to access or consume an API coded in Python, we need to upload the file on a web server.

If you are going to choose a web server, select one that has got good support for Python. There might be many free web servers out there but it is always good to get a paid one with minimum cost. the reason being the support offered from a paid server is awesome. They normally have 24 hrs support with live chat which is great 🙂 . since it is quite inevitable that you might get stuck somewhere in your project and more often than not the reason would be the server. Sometimes you are not familiar what the server is capable to do and that’s when you need to ask question to the experts. It saves a great deal of time and effort as opposed to figuring it out on your own.

Python has many projects for deployment of code, CGI is one of the oldest and it is still used. If you are planning to use the CGI project then the code has to be saved in the cgi-bin directory of your server. The extension should be .py . In order to load this file on your web browser just use the file location. For example http://www.samplehost.com/cgi-bin/hello.py

Many times you might get an error at this point and most commonly it is the Internal Server Error. There could be many reasons why that error has occurred. I will be blogging in detail about that. One of the possibilities could be an error in your code itself. It could be a missing parenthesis or some syntax error. But once you are able to figure out the errors, more often not the code should run without any Issues 🙂 .

Python Implementations

Python is a widely used scripting language. And over the years has got different Implementations. Some of the web hosting servers which mainly focus on PHP do not support all the Implementations. Hostgator is one such web server which supports 2 Implementations of python – CGI and mod_python.

Some of them support more. If your intention is to access Internet resources like API’s then it would be always good to choose a web hosting service that has got a good support for Python. And even if you have to pay for the hosting, it shouldn’t be much of a worry since it would benefit you in the long run. One gets live tech support through the most part of the day which comes in handy if you are facing an Issue.

Running Python code on a hosted server

Python just like any other back end programming language needs libraries in order to function. In order to run your python code, it has to be hosted on a server. It can either be your local server or an externally hosted server.

Fortunately servers already have the Python libraries pre-installed and configured. So one does not need to Install anything in order to make it run.

To execute your python files on the server it has to be placed in a special folder. It is called the cgi-bin folder present under the home directory. As you place these files in the folder one must ensure that the file extensions are .cgi  and not .py.

Once you get this far you are now in a good position to play around with your code and see how it works! 🙂

Python Intro

Python is quite a robust and dynamic language. It is very useful in writing scripts. Like any other scripting language, it can be used to automate certain tasks.

In most languages the file extension s start with the first letter of the word or sometimes the whole word. For example, the file extension for the C language is .c , for c++ it is .cpp and for java it is .java.  Python uses a similar naming convention for it’s extension. It uses the first two letters of the word and hence it is named as .py .

Python unlike other programming languages do not use braces to denote a block. Blocks are mainly represented using indentations. And one has to be very careful in using them. Since in python if a set of statements have to be defined in a block each line of that block should have the same amount of spacing.