0% found this document useful (0 votes)
16 views15 pages

Installation

It's installation of Vs code

Uploaded by

Shivu Shivu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views15 pages

Installation

It's installation of Vs code

Uploaded by

Shivu Shivu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Installation, Django Setup and File structure

STEP 1: Install python type “python download” click the first link and download
the python for windows

Click on windows installer 64bit link

 After download check the below checkboxes then click on install now
STEP 2: Install vscode by giving “visual studio code download” in
chrome click the first link then download for windows

 Click the radio button I accept the agreement

 Check all the check boxes and click next


STEP 3: Create folder for Django Projects
DjangoProject1 is my folder

STEP 4: Open Vscode and click on open folder and select the
Djangoproject folder which you have created
 Open new terminal
 Click on dropdown beside powershell and select “command
prompt”
 Change path to desktop and folder which you have created

STEP 5: Now path is changed to your Projectfolder, next you have to


created the Virtual Environment for the Django Projects
 Creating a virtual environment for a Django project keeps
dependencies separate, making it easier to manage and ensuring
that the project works consistently across different computers. It
also enhances security by preventing conflicts with other
installed software.
 Command to create Virtual environment is “python -m venv
myenv”
 myenv is the virtual environment name.
STEP 6: Check whether myenv is created or not
This is my project folder

myenv is created successfully created inside the DjangoProject1 folder


 Now we need to activate the myenv by giving the below
command

myenv\Scripts\activate
STEP 6: Install Django by giving below command

pip install django

STEP 7: Create a project inside the folder by giving the


command “django-admin startproject MysoreBank”
 Check whether project created in folder or not

Project “MysoreBank” is created inside the DjangoProject1


folder
STEP 9: Change the directory to your current project by giving
“cd MysoreBank” Django provides lightweight server to run your
project if you want to run your developed project you need to give
the below command
python manage.py runserver
In the MysoreBank project, you can run this command without having
developed anything, and the default page will be displayed. From
there, you can proceed to develop your project according to your
specific requirements.

Click on the ip address and you will get this output in browser

Now you have successfully installed, made a setup and run the project
now you can coustamize your project according to your requirement.
Mapping URL to Views and creating first App in Django

After successful installation and setup next thing is to create first app
in Django which display “hello world” in web browser

STEP 1: Open Vscode select your project folder open terminal and
select the command prompt
First change your directory to the project created in this case
MysoreBank is the project name
cd MysoreBank
Then create the app by giving below command
django-admin startapp myapp1
myapp1 represents the app name
Then check whether app is present inside the MysoreBank folder

STEP 2: click on MysoreBank  myapp1MysoreBank


STEP 4: click on myapp1  New File Icon
You will find one Textbox in myapp1 give name as “urls.py”
STEP 5: urls.py file is created in myapp1 App now type the below
code inside the urls.py file in myapp1

from django.shortcuts import render


from django.http import HttpResponse

# Create your views here.


def myfun(request):
return HttpResponse("hello world")

urls.py (myapp1):

 This file defines the URL patterns for the myapp1 App.
 from django.urls import path: Importing the path function from
django.urls.
 from . import views: Importing the views module from the current
directory.
 urlpatterns: A list of URL patterns.
 path('', views.myfun, name="home"): Maps an empty URL to the myfun
view function from the views.py file within the myapp app, and assigns
the name "home" to this URL pattern.
STEP 6: Now open views.py file in myapp1 and type the below code

from django.shortcuts import render


from django.http import HttpResponse

# Create your views here.


def myfun(request):
return HttpResponse("hello world")

views.py (myapp1):

 This file contains the view function myfun.

 from django.http import HttpResponse: Importing HttpResponse from


django.http.

 def myfun(request): Defines the view function myfun, which takes an


HttpRequest object as a parameter.

 return HttpResponse("hello world"): Returns an HTTP response with


the content "hello world".
STEP 7: Now open urls.py file in MysoreBank project and type the
below code

from django.contrib import admin


from django.urls import path,include

urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myapp1.urls'))
]

urls.py (Mysorebank):

 This file defines the URL patterns for the entire project, including the
myapp1 app.

 from django.urls import path, include: Importing the path and include
functions from django.urls.

 from django.contrib import admin: Importing the admin module.

 urlpatterns: A list of URL patterns.

 path('', include('myapp1.urls')): Includes the URL patterns defined in the


urls.py file of the myapp app. This means that URLs matching those
patterns will be handled by the views defined in myapp.

 path('admin/', admin.site.urls): Maps the URL /admin/ to the Django


admin interface.
Now run below command in terminal to execute the project

Python manage.py runserver

In Mysorebank/urls.py, the empty path(' ') is linked to the URL patterns defined
in myapp1.urls, meaning that when a user visits the root URL of the website,
Django will look for further URL patterns in myapp1.urls.
In myapp1/urls.py, the empty path (' ') is mapped to the myfun view function.
Therefore, when a user visits the root URL, they will see the "hello world"
response generated by the myfun view function in views.py.
This is how the mapping of URLs to view functions is done in a Django
application.

You might also like