Learning Django - 2

This is the second post among a series of posts about my django learning experience.

I'll start clean and set things up for the whole development process. I'll be using, Ubuntu, Python 3 (https://www.python.org/downloads), virtualenv (https://virtualenv.pypa.io) so that I don't have any dependency conflicts with my other projects, pip for installing these tools and obviously django. Considering that I have the latest python 3 installed (pip comes packaged by default), I ran the following command ($ denotes a terminal session):

$ # Use the sudo command if necessary (only applicable for *nix systems, n/a for windows)
$ [sudo] pip install virtualenv
$ virtualenv virtual_folder
$ cd virtual_folder
$ source bin/activate

This installed virtualenv (short for Virtual Environment) and created a directory named virtual_folder for holding the new virtual environment. cd-ed into it and activated the virtual environment. Deactivating is easy, just run deactivate and it'll deactivate itself. Next, I'll install django with this command:

$ [sudo] pip install django

After django is installed, a terminal restart was needed to load in the new binary. Then I created a project named website with this:

$ django-admin startproject website

A new directory named website is created in the current directory. This contains all the necessary backbone for running a simple django server. cd (change the terminal's directory to point to it) into it. Now, the initial configuration is done and its time for a test run! Run this command:

$ python manage.py runserver

And it should start a server in the localhost at port 8000 or whichever is printed in your terminal. Visit: http://127.0.0.1:8000/ to view the new django server up and running! I'll be explaining in short, what each file is and why its necessary in my next post.

This is it for the initial setups.

No comments:

Post a Comment

Power function

In C/C++ (and also other languages), we have the built in power function to raise a number to a given power. What if we need to calculate ...