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 line utility to add new apps.
django-admin startproject myproject
This command will create new files on disk for our new project which are explained below :-
myproject/ manage.py myproject/ __init__.py settings.py urls.py wsgi.py
Outer myproject folder is just a container folder which can be renamed to any name without having any impact on the Django project.
manage.py is command line utility for this Django project, which will be used for interacting with this project (common operations are adding new apps, running development server, database operations and so on)
Inner myproject is a Python package whose name will be used while importing containing files. __init__.py inside this folder makes this a Python package.
myproject/settings.py is the configuration or settings file for this Django project.
myproject/urls.py is the URL maaping/lookup file for this Django project.
myproject/wsgi.py is used for hosting this project at WSGI servers.
Now that our project has been created, we will use the manage.py from the project structure to add our first app.
python manage.py startapp myfirstapp
Let's get started by installing Django (I am using 1.11 at the time of writing this). Once the Django is installed, a new project is created using the django-admin command.
myfirstapp/ __init__.py admin.py
Comments
Post a Comment