This tutorial will be relatively short. We will see only the installation part of Django. Now the question is, what is Django?
What is Django?
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.
Installation
First install Django from your command prompt. Open your command prompt and run the following command:
$ pip install django Downloading/unpacking django==1.8 Installing collected packages: django Successfully installed django Cleaning up...
Let’s create a new folder called “django” anywhere you want. And go to that folder with your console. Run the following command. Don’t forget give the dot(.).
$ django-admin startproject blog .
The following files have created inside django folder.
manage.py: is a script that helps with management of the site. With it we will be able to start a web server on our computer without installing anything else, amongst other things.
settings.py: file contains the configuration of your website.
urls.py: file contains a list of patterns used by urlresolver.
Now open settings.py with your IDE. Add the STATIC_ROOT just after the STATIC_URL.
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static')
The following lines contain the database configuration. We are using sqlite3 for our database. db.sqlite3 is our first database and the location will be our project directory.
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
Now run the following command to create our database and tables.
$ python manage.py migrate
If everything is OK, you should see something like the following –
You may see the following changes happened in your installation directory.
Yes. db.sqlite3 has created, right! But it contains? Right..
Firefox has a wonderful add-on for SQLite called, “SQLite Manager”. You can download it from https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Add it to your Firefox and open db.sqlite3 –
Total 11 tables are created for user and admin control.
Till now we don’t have any user. Let’s create a super user first.
Run the following command from the console –
$ python manage.py createsuperuser
This command has created a admin user with given email and password.
Now check your database again – to get the idea about the created user. One user has created named admin and his password is hashed.
Now let’s run our server from command prompt –
$ python manage.py runserver
Open your web browser and go to –
http://127.0.0.1:8000
and,
http://127.0.0.1:8000/admin
What you see? A full-featured admin dashboard has created. Play with it and see what it can do.
Happy coding… 🙂
Django
Hej, I’m from Bangladesh. Learning programming is one of the freaking decisions I have taken in my life. Because, it makes me and my life crazy. I have great weakness on open source technologies. Perhaps, that’s why I do not know any closed source language. I fall in love with programming, when I started my undergraduate in East West University. Till now, I can not live without it.