Installation
Installation
STEP 1: Install python type “python download” click the first link and download
the python for windows
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
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
myenv\Scripts\activate
STEP 6: Install Django by giving below command
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
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
views.py (myapp1):
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.
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.