Category Archives: Python

create-class-based-view-in-django

Create class based view in django 3

Hello World, Welcome to projects plaza.com. Today we will learn how to create a class-based view in Django 3. In this tutorial, we will render a simple template via class. Basically, there are two methods to load the view template in Django. One is a function-based view(FBV) and another is a class-based view(CBV). Class-based views were introduced in Django 1.7. The reason behind this was the proper structure, inheritance and the developer can customize the class-based view more than the function-based view.

  • Create cbv.html in the templates folder in your app and add the following code.
  • <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>CBV View</title>
    </head>
    <body>
        <h3>Hello World, This is class based view</h3>
    </body>
    </html>

     

  • Open app/urls.py and add the following code in it
  • urlpatterns=[
        ...
        path('cbv',TemplateView.as_view(template_name="cbv.html"))
    ]

     

Python example 3 – Solver number power

Hello World, Welcome to projectsplaza.com. In this example, we will calculate the power of the number. We will take the number and power from the user and calculate it with python function. We will do this in the following steps.

  • define power_multiply function
  • get to input from the user number and power
  • calculate the number of power with ** expression
def power_multiply():
    number=int(input('Enter the number '))
    power=int(input('Enter the power '))
    print(number**power)
power_multiply()

Output of this example

power_multiple_in_python

summing_numbers_in_python

Python Example 2 – Summing Numbers

Hello World, Welcome to projectsplaza.com. In this tutorial, we will create a custom python function to show the sum of the provided numbers. This function takes a sequence of numbers and shows the sum of those numbers. This exercise helps you to understand numbers and function design.


Continue reading

number-guessing-game-in-python

Python Example 1 – Number guessing game with python

Hello World, Welcome to projectsplaza.com. Today we will discuss how to create a number guessing game with python. This tutorial is for python beginner. Python has three different numeric types: int, float, and complex. Most of the time, it is enough to know about int(for the whole number) and float(for fraction number). For this game, we will do the following steps

  • Write a function guess_number that takes no arguments.
  • When we run this function it will automatically choose the number between 0-50.
  • Ask the user to guess what number has been chosen.
  • Every time user guess a number, we will indicate the following:
    • Too High
    • Too Low
    • Just Right
  • If the user guesses the correct number then the program exit, otherwise the user is asked to try again.
  • Programm will exist only if the user guesses the correct number.

Continue reading

How to save form data in database in django

Hello World, Welcome to projectsplaza.com. Today we will learn how to save form data in the database in django. We will use the SQL database. I am assuming that you have installed Django in your system, If not then please refer to this tutorial. We will create a simple contact form in which the user will fill his basic information like full name, email, and message.
I have divided this tutorial into the following parts.

  • Create a contact model
  • Create contact form template
  • Submit form and save data in the database

Continue reading

How to create admin panel in django 3

Hello World, Welcome to projectsplaza.com. Today I am going to create a tutorial about the Django admin panel. In this tutorial, we will learn how to create an admin panel in Django 3. I will extend my previous tutorial in which we have learned how we can submit form data in the SQLite database with jquery ajax in Django 3.

Django comes with a powerful admin panel. We just need to configure this in our project. There are lots of features in this admin panel but not any then you can customize it at any level.

Continue reading

how-to-submit-form-data-with-jquery-ajax-in-django

How to submit data with jquery ajax in django 3

Hello World, Welcome to projectsplaza.com. Today I am going to create a tutorial on how to submit the form with jquery ajax in Django 3. This is a very simple tutorial. I will submit a form of data in the database without reloading the page in Django 3 with the help of jquery ajax. I have divided this tutorial into the following steps.

  • Setup Django with learning project and ajaxform app
  • Create a post model
  • Setup route for view
  • Create form template
  • Submit form data in the database with jquery ajax
  • Verify the submitted data

Continue reading

How to create static application with django?

Hello World, Welcome to projectsplaza.com. This is the third tutorial of the series “learn Django from scratch with example“. In this tutorial, we will create a static blog application with Django. We will learn the following things in this tutorial.

  • How to create view templates in Django?
  • How to add static files in Django templates?
  • How to extend a template in Django?
  • How to share common data in all views?

Continue reading

how-to-create-project-and-application-in-django

How to create project and application in Django?

Hello World, Welcome to this website. This is the second tutorial of the series “learn Django from scratch with example“. I have divided this tutorial into the following parts.

Continue reading

what-is-django-and-how-to-install-it

What is Django and how to install Django?

Hello World, Welcome to projectsplaza.com. This is the first tutorial of “learn Django from scratch with example“. In this tutorial, we will discuss “what is Django and how to install Django“.


What is Django?

Django is an open-source web application framework, built with python. A web framework is set of components which help to create web application easier and faster. Django follows the model-template-view architectural pattern. It is maintained by the Django Foundation. The main goal of Django is to create a database-driven and complex website with ease.

Continue reading