Create A Website From Scratch Using Django
With each passing day, we are seeing an influx of new websites in the virtual space. There are a number of solutions out there that can make the task of web development easier. Catering to the need of quicker web development, web frameworks like Django are becoming increasingly popular. If you are on a deadline or want to create your websites in the shortest amount of time possible, you can employ this web framework and hasten your web development tasks.
Django is a Python Web Framework that facilitates quick development and has a clean and pragmatic design. By learning Django, one can get into the IT industry and earn a handsome salary package. According to indeed.com, the average salary of Python Django Developer is estimated at a respectable $116,018 per year. The pay package by itself is reason enough for web developers to learn python django from scratch and master it.
The following is a step by step procedure that can be utilized for creating a Django website from scratch:
1. Create Your First Django Project (iFriends project)
a) From the command prompt, go to the directory that you want to use for storage of the code for the iFriends project.
b) Build a directory called iFriends as the root directory for the project.
c) Go to the iFriends directory.
d) Use “python django-admin.py startproject iFriends” as a command for creating the iFriends project
2. Start the Development Server
3. Configure the Database
4. Construct the Database and Give Rights
5. Configure Django for Accessing the iFriends Database
6. Synchronize the iFriends Project to the iFriends Database
7. Install an Application
8. Add the Data Using the API
9. Set up the URLConf File
You can use the example mentioned below for setting up the file in the step number 9:
a) Open the iFriends\urls.py file in an editor.
b) Search for the urlpatterns setting, and add the iFriends.People.views.index pattern:
urlpatterns = patterns('',
c) Save the file.
10. Creating a Simple View
Once URLConf file is configured, you are required to add the views to the application. The application's views are saved in the views.py file. When the Django server gets a URL request, it parses and finds out the function that needs to be executed for generating the web view.
Once the view is created, you can view the web page through the development server.
- Open the iFriends/People/views.py file in an editor. The views.py file is empty at first.
- Use the editor for adding the following code to the file:
From django.shortcuts import HttpResponse
From iFriends.People.models import Person
html = "<H1>People</H1><HR>"
- Save the file
- Use cmd prompt to change the root directory for the project
- Now use the command below for kick starting the server:
python manage.py runserver
- Access the http://127.0.0.1:8000/People URL. Performing this step will show you the page that you have created.
By following the aforementioned example (courtesy of codeproject), you can develop a sample website that can be the stepping stone for higher learning.
Advantages of Django
There are many advantages of Django, which is the reason why most people learn django from scratch. Some of the advantages of Django are as follows:
Django Is Fast And Secure
You can take your idea into development in the shortest time possible. When you use Django, there is less scope of committing common security mistakes like cross-site request forgery, clickjacking, and SQL injection.
Django Is Versatile And Scalable
You can manage scientific computing platforms and content easily while using Django. With this web framework, you can handle heavy web traffic easily as it is quite scalable.
Django Is Comprehensive And Fully Loaded
It comes with a lot of extras that can help you handle all aspects of different tasks without any need to go to a different platform.