top of page
  • Priyanka P. Pattnaik

Django - The web framework


After reading the blog, you can easily find how we should go for Django and it is a friendly framework to work on. I am going to explain


1. what is Django?

2. Why we should choose Django?

3. What is the advantage of choosing it?

4. How to start work?


~~ As per the definition of Django, it is a high-level Python web framework that enables the rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. ~~


The above is the proper definition that gives you a feel about how efficient it is. let me break down it for you as per my understanding Django is a package in python like any other package which provides certain python files to host your program.


After reading my kind of definition you can get that it is python and python is easy to learn, clean, and it's amazing. Nowadays python is a demanding language and every industry is running towards it. So why not go for it. And when you have a big project you can go for Django as it will provide you so many advantages. I am discussing below the advantages of Django to make it clear for all.


Django has so many advantages.

  1. The first one we already know. It is in python.

  2. The second one is, companies like Google, Facebook, NASA, etc. are doing it.

  3. The third one is that the batteries included which means it has so many features. It supports Ajax, RSS, Free API, URL routing, and many more.

  4. The fourth one is its large community and widely available documentation and tutorials. The administration interface provided by Django is one of the coolest things. It’s truly simple to create and it’s really one of the key advantages when using the framework. You get a fully featured admin interface from writing only a few lines of code.

  5. It is Scalable, Customizable, Robust.

  6. For security, it hides your website’s source code. The framework has protection against XSS and CSRF attacks, SQL injections, clickjacking, etc.

To start the django in your project. Like in python the first step is always to install the package. Open your anaconda prompt and give the command directly or you can make a virtual environment and then install it. The command is


python -m pip install Django

Now I believe that you have installed Django. To verify if it is installed or not. Run this on your command line.


python -c "import django; print(django.get_version())"

If Django is installed, you should see the version of your installation. If it isn’t, you’ll get an error telling “No module named Django.


In Django, we need to create the project. It needs to auto-generate some code that will connect you to a Django project. This auto-generated code is a collection of settings for an instance of Django, including database configuration, Django-specific options, and application-specific settings.


First, go to the folder using the cd command to store your code. And run this command on your command prompt. Where mysite is the name of your project.


django-admin startproject mysite

You can see in your current directory that a mysite folder is created with so many applications that are included by default as a convenience for the common case.


Some of these applications make use of at least one database table, though, so we need to create the tables in the database before we can use them. To do that, run the following command.


python manage.py migrate

To verify your project run the following command


python manage.py runserver

you will get something like


System check identified no issues (0 silenced). December 01, 2020–09:57:57 Django version 3.1, using settings ‘mysite.settings’ Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.



Hurrah, If you get this then you have established a project in Django. If you are reading this blog then I will assume that you have created the project successfully and now you are interested in doing more with it.




Now that we have set up a project let's start our actual work.


Django helps us with automatically generates the basic directory structure of an app so that you can directly focus on writing the code rather than creating the directories.


Let's create your app. Before giving the command just make sure that you are in the directory you’re where you can see the manage.py and now run the following command.


python manage.py startapp dqapp

It will create a directory dqapp which have some automatically-generated files. You can make some folders as templates, static, media as per your requirements, and below is the overall structure of your whole project.



I am writing this blog by using so many reference sites and youtube videos. As I am sharing my experience with Django. In my next blog, I will tell you about how to set up URLs and connections between HTML and the python code. Thank you for reading it and coming with me so far.


Brought to You by-

COE-AI(CET-BBSR)- A Initiative by CET-BBSR, Tech Mahindra, and BPUT to provide solutions to Real-world problems through ML and IoT

70 views0 comments

Comments


bottom of page