Introduction
Web Development is one of the most popular fields in the world of programming. Beginners in programming often want to use Web development as a starter to reach where ever they want to go in Software development. But some people find Web development very interesting and would love to go in-depth into Web Development. There are several languages and frameworks that support Web Development such as PHP, JavaScript, Django, Flask, Ruby, and so on. I want to talk a little about Django and show you the steps of starting a Django project.
What is Django?
First of all, What is Django? Django is a Python-based free and open-source web framework that follows the model–template–views architectural pattern. It is maintained by the Django Software Foundation, an independent organization established in the US as a 501 non-profit. It was released on 21st July 2005. There are other web frameworks based on Python such as Flask, Web2py, CherryPy, and so on. At the time of the writing of this article, Python has 11 frameworks for Web development. But Django seems to be more preferred when talking about Web Development with Python.
Reason why Django is more preferred for Web Development with Python
###- Django Supports MVC Patterns This framework supports MVC pattern that permits little enterprises to modify and speed up the event method of complicated web applications by keeping their business logic and user interface layers separated. however, Django implements it in a bit different manner. It enables programmers to handle templates while taking care of the controllers. Therefore, the developers aren't needed to focus on the interaction between the model and also the view. they merely need to map the model, view, and template it to a selected URL.
Django Supports Both SQL & NoSQL Databases
Some marketers pick out conventional relational database structures however others decide on NoSQL databases. Django makes it less complicated for small marketers to choose from a big range of databases with the aid of using imparting an object-relational mapper (ORM) system. This device bridges the space between the database engines and the data model. This makes it smooth for small organizations to apply relational database control structures which include MySQL, Oracle, PostgreSQL, etc. Also, they are able to use the ORM device so that you can paintings with NoSQL databases which include Google App Engine and MongoDB.
Exclusive Built-in Template System
Django comes with an integrated template mechanism that allows programmers to maintain the codebase maintainable through preserving Python and HTML code separated. They can use this template system to encompass Python code in perspectives and HTML code in templates. Also, it permits developers to attach the templates and perspectives seamlessly with the assist of Django template language or render functions. With the assist of the mini-language supplied through the template engine, it becomes less difficult for the programmers to outline the internet application’s consumer interface layer.
Availability Of Fully-Featured Admin Interface
Django additionally gives a ready-to-use and completely featured admin interface. It in addition generates the admin user interface routinely and dynamically on the idea of the task model. It permits small business entrepreneurs to carry out internet site administrative and control obligations without problems. Also, the builders can without problems personalize the admin interface according to unique enterprise needs.
How to set up a Django Project
Install Python Interpreter
Download the Python Interpreter from the Python website
Install Django
Press Win + R, type 'cmd', and press ENTER. Type,
pip install django
Create a project
Navigate into the directory you want your project to be stored. Then type,:
django-admin startproject {your-project-name}
Here, I would choose my project name to be "myapp". So I would type:
django-admin startproject myapp
, then press ENTER.
This would create a folder with the name of your project.
Now we have to navigate into the folder. In there you would see a folder with the same name as your project and a file named "manage.py". Now that we have our project let’s create an app and the initial database:
python manage.py startapp {your-app-name}
. Here, my app name would be 'home'. So I would write:
python manage.py startapp home
This would create a folder named "home" in your project. Now we can check if our setup worked by running it on a server. Django comes with an inbuilt server that can be used to run your app locally.
Launch the server
python manage.py runserver
It would give you a URL to open it on your browser locally. Open it and you should see a welcome page saying that the installation worked successfully.
Conclusion
You have fully set up the project for you to start building your web apps. In later articles, we would go into adding your own pages and adding the sqlite3 database into your project. If you have any issues with the installation and setup, you can drop the issue in the comments and I would reply to you as soon as I can. That's all for now and see you in my next post...