Django is a Python-based web framework which allows you to quickly create web application without all of the installation or dependency problems that you normally will find with other frameworks. When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. Django gives you ready-made components to use.
- Django is a rapid web development framework that can be used to develop fully fleshed web applications in a short period of time.
- It’s very easy to switch database in Django framework.
- It has built-in admin interface which makes easy to work with it.
- Django is fully functional framework that requires nothing else.
- It has thousands of additional packages available.
- It is very scalable. For more visit When to Use Django? Comparison with other Development Stacks ?
Installation of Django
- Install python3 if not installed in your system ( according to configuration of your system and OS) from here . Try to download the latest version of python it’s python3.6.4 this time.
- Install pip- Open command prompt and enter following command-
- Install virtual environment- Enter following command in cmd-
- Set Virtual environment- Setting up the virtual environment will allow you to edit the dependency which generally your system wouldn’t allow. Follow these steps to set up a virtual environment-
- Create a virtual environment by giving this command in cmd-
python -m virtualenv env_site
- Change directory to env_site by this command-
- Go to Script directory inside env_site and activate virtual environment-
- Install Django- Install django by giving following command-
pip install django
- To initiate a project of Django on Your PC, open Terminal and Enter the following command
django-admin startproject projectName
- A New Folder with name projectName will be created. To enter in the project using terminal enter command
- To create a basic app in your Django project you need to go to directory containing manage.py and from there enter the command :
python manage.py startapp projectApp
- Now you can see your directory structure as under :
- To consider the app in your project you need to specify your project name in INSTALLED_APPS list as follows in settings.py:
- So, we have finally created an app but to render the app using urls we need to include the app in our main project so that urls redirected to that app can be rendered. Let us explore it. Move to projectName-> projectName -> urls.py and add below code in the header
from django.urls import include
- Now in the list of URL patterns, you need to specify app name for including your app urls. Here is the code for it –
- Now You can use the default MVT model to create URLs, models, views, etc. in your app and they will be automatically included in your main project.
Share your thoughts in the comments
Please Login to comment...