Skip to main content

Getting Started with Django: Building Web Applications with Python

Getting started with Django part-01

 Django is a high-level, powerful Python web framework that enables the rapid development of secure and maintainable websites. Here are the steps to get started with Django:

Install Python: Before you can start using Django, you need to have Python installed on your system. You can download the latest version of Python from the official website: https://www.python.org/downloads/ 

Install Django: Once you have Python installed, you can install Django using pip (a package manager for Python) by running the following command in your terminal: 

Pip install django

 Create a new Django project: You can create a new Django project using the following command in your terminal: 


django-admin startproject “name your project” 

For example:- django-admin startproject myproject 

This will create a new Django project named myproject. 

Create a new Django app: A Django project can contain multiple apps. You can create a new app using the following command in your terminal: 

python manage.py startapp myapp 

This will create a new Django app named myapp. 

 Create a view: A view is a Python function that takes a web request and returns a web response. You can create a view in myapp/views.py file. Here's an example view: 

from django.urls import path
from . import views

urlpatterns = [
    path('hello/', views.hello, name='hello'),
]

Create a URL route: A URL route maps a URL to a view. You can create a URL route in myapp/urls.py file. Here's an example URL route:  

from django.urls import path
from . import views

urlpatterns = [
    path('hello/', views.hello, name='hello'),
]

Run the development server: You can run the development server using the following command in your terminal: 

                                           python manage.py runserver 


This will start the development server at http://localhost:8000/. 

 Test the app: You can test the app by visiting http://localhost:8000/hello/ in your web browser. You should see the message "Hello, world!". 

Please make sure to add the name of your app to the INSTALLED_APPS list in the settings.py file of your Django project. 


INSTALLED_APPS = [
    'myapp',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'django.contrib.humanize'
]


These are the basic steps to get started with Django. From here, you can explore the Django documentation to learn more about building web applications with Django.

Comments

Popular posts from this blog

Random Password Generator Using Python

  A  random password generator  is a software program, hardware device, or online tool that automatically generates a password using parameters that a user sets, including mixed-case letters, numbers, symbols, pronounceability, length, and strength. Here is the simple python code to generate password randomly. #random module import  random print ( "=================\nPassword Generator\n=================" ) print () #you can use more character here characters =  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@_#$%&*0123456789" #Input  Number of password Num_Of_pass = int( input ( " How many passwords do you want?: " )) # Input length of password len_Of_pass = int( input ( ' Enter lenth of password you want to generate : ' )) print () print ( "Passwords are: " ) print () #for Number...
Smart AI Solutions for Daily Life: From Fitness and Shopping to Legal Document Review AI Fitness and Diet Planner The following topic develops an AI-based fitness and diet planning application. Generally, at large, people visit fitness centers but do not know about the routine of keeping good fitness and accurate diet planning. Both the aspects are required to be known for maintaining health and wellness. The AI Fitness and Diet Planner will be able to provide customized workout routines, suggest balanced diet options, recommend daily intake quantities of food, and advise on optimal meal and fitness timings. Further, integrating features such as reminders, tracking progress, and adaptive diet plans will facilitate users in making informed lifestyle choices toward a long, healthy life.   AI Based Personal Shopping Assistant   This research investigates the development of an AI-powered personal shopping assistant for efficient financial management and considerate shopp...