Blog

Hack – Django Website Tutorials | Building Complete Website with Django

Django Django Tutorials

Hack – Django Website Tutorials | Building Complete Website with Django

Practical Tutorial | Building Complete Website with Django | Django Website Tutorials

We have published many tutorials related to Django, in which we discussed different Django topics as templates, Models, Forms, URL, Views, ORM, Middleware, etc. But today, It is decided to write Django website tutorials in which we will share knowledge related to Creating a Website with Python Django, each and everything. So you have to read this tutorial from start to end if you want to really learn! Let’s start!

Django is the Python-based web framework in which a developer can create a more functional website. As you JafriCode provides tutorials in the easiest way and simple ways with relevant examples. As discussed in the first paragraph that we have created a website with the Python Django framework.

We select Django because it has more features that have not in another web framework as it is written in Python. You Python is the most famous and powerful programming language. Because, if you want to enter the field of web development then you must know how to create a website with different techniques e.g WordPress, Codeginiter, etc But we are learning Django right now. let’s start Django website tutorials with guys!

There are different things you have to know for creating a website with Django. First of you should know the prerequisites of Django. To help students we publish a tutorial on this topic also if you don’t know.

Application vs Project in Django

If you know, we have published a Django tutorial in which we explain what is difference between the Django project and application. You have listened project and application, do you know about that? Project is created when starting a project using the command. After creating the project we get different files as  manage.py,  __init__.py, settings.py, urls.py, asgi.py, wsgi.py.

If you follow the below steps while creating website learning Django website tutorials, you will be confused less. Anyhow, you have problems/issues, you can share them with us without hesitation. We will provide the best solution for you InshaAllah.

We start Django Website Tutorials Right Now!

1) Install Python

At first of all, you need to install Python if you want to go to the Django Web framework. Because Django is the framework that is written in the Python programming language. To install I tell you in very short steps, you have to just follow:

  • Go to Python official website
  • Click on Download latest version
  • After downloading, then install it
  • While installing must check the checkbox ‘Add to Path’
  • To check wheater Python wheater it is installed or not, then type python in cmd, if you got python related information then python is installed in your system

2) Install Django

To take Django website tutorials complete, follow our steps as we discussing. Now you have to install Django, which is very easy to do. You know, Django is a Python-based package. To install a Python-based package we need PIP. Pip is the package management system that is built-in in Python.

To install Django you have to open cmd and run the following command:

pip install Django

If you want to learn complete Django, then we have published complete tutorials.

3) Start a Project

After installing Django, the first work you to do is to start the project. Project is the complete program in which different applications are linked to each other. For example, you want to build a school project, then registration, fee management, sports, and other department are the different applications. So there are multiple applications in one project.

So to start a project run the following command:

django-admin startproject projectName

4) Create Application

We have learned what is the difference between Django application and project at the starting of this article. In Django website tutorials, we will clear each and everything you need. As we are at step4 to creating an application in Django. After creating a project you need to start an application. The following command is used to start an application

python manage.py startapp user

It means we are creating an application named user in the school project. It indicates that all the functions related to the user will be store in the user application.

5) Include in settings.py file

It is very necessary to add the application you created now in the settings.py file. To add an application in the settings.py file means, you are telling to Django that we created an application and behave with it.

You have to go to the settings.py file of your project file, then go to the INSTALLED_APPS list, in which you will note tath other by default applications are also mentioned you have to add your own application as you created now.

INSTALLED_APPS = [
‘user’
]

In INSTALLED_APPS contains the following default apps, all of which come with Django installation.

INSTALLED_APPS = [
‘django.contrib.admin’
‘django.contrib.auth’
‘django.contrib.contenttypes’
‘django.contrib.sessions’ 
‘django.contrib.messages’ 
‘django.contrib.staticfiles’ 
]

6) Create an urls.py file in the Application

As you know we are discussing Django website creation in Django website tutorials that will be more beneficial for you if you take interest in reading and implementing. So continue to reading! After completing the above steps, now you have to create separate urls.py files for your application’s web page URLs.  One urls.py file is generated by default when you install the Django web framework, but for your application, you have to create urls.py separately.

It is not required but most recommended to create. Because when you build an application with Django project without creating urls.py file separately for application, then it will be very difficult to move your application to another Django project because your application is located in another place and application URLs are located in another file.

jafricode url file - django website tutorials

So you need to create urls.py file separately in the application, when you want to move your application to another Django project then you did need to worry because all the URLs patterns will with your application as located in the applications urls.py file.

7) Add URL reference in project URL file for the Application

urls.py file is come with Django by default in the project folder but you can build an urls.py file for your specific application and then link to the project’s urls.py file. It is very simple and beneficial to do. So follow the below discussion:

  • First of all, you have to create a file named urls.py in the application folder
  • Then open projects’s urls.py file
  • link your application’s urls.py file in the path function providing some arguments as discussed below:

The following code will help you, must understand!

# urls.py of your project folder

from django.contrib import admin 

# You need to import admin, it is for backend database purposes for admin
from django.urls import include path

# you need to import include because you want to include your application’s urls.py file and path function which create a complete path for your web page URL

urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘testapp/’, include(“testapp.urls”))

# This line is used to connect urls.py of your application in the project’s urls.py file

#When anyone type ‘user’ then it will be forwarded to applications’ urls patterns that are located in the application folder.
]

8) Create a Django Template

After attempting the above steps, you need to create a Django template for your website homepage and for other web pages. To do that, you have to create a template folder inside your application folder.

In your proejct folder> applicaiton folder> create template folder > give name as your applicaiotn folder> index.html

In your index.html file

<!DOCTYPE html>
<html>
<head>
<title>Web Page Title</title>
</head>
<body>

<h1>Your first Django Application</h1>
<p>This is your web homepage</p>

</body>
</html>

This file you need to render in views.py file. When the user hits the specific URL for this web page, then a request make and goes to the server, after reading the user message, the server gives a response in the views section and then renders a template, displaying the template as above.

The Django template language is the language that is used in the Template when need. Actually, it is the language between Python programming and HTML coding.

9) Create View Function for Specific Web Page

In the application views.py file, you have to create a view for your web page in which you can make logic, programming goals, anything you want. And also you can render a Django template in the view section.

from django.shortcuts import render
def index(request):
    return render(request, ‘users/index.html’)
We created an index function, in which we simply write a line that renders a template with a render function. Render function has two parameters, in this case, one is requested which is requesting to a server, and the other is a path for your template.

10) Create URL for Views

from django.urls import path, include
from . import views # it means you are importing views from the current application, If the view is importing from another application then you have to use from appname import views.
urlpatterns = [
    path(‘ ‘, views.index, name=”index”)
]
To create a URL you have to use the path function which takes some arguments.
The first argument is showing the path, in this case, you did not need to add an extra path when you enter the main domain then your view will run.
And 2nd argument is showing the view function for which you are creating a URL. In this path, we are mapping the URL with the view function.
3rd argument is showing the name of URL used in the template for creating the URL tag.

11) Run the Server

We have completed django website tutorials right now, it is the last step you have to follow. When you complete anything else you have to run the server at the last. If you have done all the steps completely as we discussed, then your server will run now when running a command which I am sharing with you!

Complete Guide

How to run a Django server

In the command prompt or visual code command prompt, you have to run the following command.

python manage.py runserver

You will get a link

http://127.0.0.1:8000/

When you enter the above URL in the browser box you will get a successful message that your Django is installed properly

Django installed jafricode

End to Django website tutorials, now you can extend it as you. So, it is the very simple website you have built, you need to add more features, functionality to your new Django website. You can create a Form, in which users input data as required. After submitting data, save it to the database table. So if you require any data you want to get from the user, then create a form.

Tutorials related to Django Form, you need to take

Full Explanation of Django Form | Django Tutorials 

Complete Built-in Django Form Fields with Examples | Django Tutorials

Django Form | Render Form Field Manually | Django Tutorials

What is CSRF (Cross-Site Request Forgery) and Why use in Django Form

To creating a form is not enough, you also need to make a database table in which user data will be store there. To create a database table, we need to make a model class with required fields that convert to a DB table. All about the Django model, you can read the following tutorial.

Complete Django Models | Django Tutorials

Conclusion

If you use Facebook, Twitter, Pinterest, LinkedIn, or other social media platforms, then share this Django tutorial, if you share, more students will take the chance to learn.

After reading today’s topic, if you face any problem while reading, understanding please discuss it with us. If you have understood and have any relevant questions then please discuss with us in the following comment section.

Recommended Django Website Tutorials for Beginners

Top 20 Python Real World Applications | Python tutorials

Conceptual Guide | What is Django Middleware | Django Tutorials

What is a virtual environment for Django Projects | Django Tutorials

Why does Django need a virtual environment?

How to Create Django project in a virtual environment

Leave your thought here

Your email address will not be published.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the compare bar
Compare
Wishlist 0
Open wishlist page Continue shopping