Django for Web Development

I am a MERN developer, I have made several projects using this tech stack, also, I am a ML enthusiast currently I am learning about different python libraries that we use in data science. Along with that I am also trying to contribute in open-source projects using all the tech stacks and skills that I have mentioned above.
Installing Django
After installing Python, we can install django using this command pip install django

Creating an environment

How to run locally
To run the project locally, first we have to change our directory to "mysite". We can do so by cd mysite.
After changing the directory we may have to migrate the python file to do so we can type in this command python manage.py migrate, after this we can run the server by typing in this command python manage.py runserver, if the server is busy or already in use we can change the port by writing this command python manage.py runserver <port number>.


How to create an app to work with?
To start an application we just have to write this command python manage.py startapp <app name> and then run server on any port which is not busy.

Routing
This is the views.py file on main application.
from django.shortcuts import render # this is the default import, used for rendering templates
from django.http import HttpResponse # this is used for handling HTTP requests
# Create your views here.
def index(response):
return HttpResponse("<h1> This is the main app homepage </h1>")
we have a view function called index. It takes a single parameter named resonse (which seems to be a typo and should be response). This function is responsible for handling requests to the main app homepage.
Inside the index function, we see a single line of code that returns an HttpResponse object. The HttpResponse object is initialized with a string that contains an HTML heading <h1> This is the main app homepage </h1>. This means that whenever a user accesses the main app homepage, this function will be called, and the specified HTML heading will be displayed as the response.

The line from . import views is a Python code snippet from a file called urls.py. This line is used to import the views module from the current package or directory.
In Django, the urls.py file is responsible for defining the URL patterns and associating them with corresponding views. The views module contains the view functions that handle these URL patterns.
On mysite module we have another urls.py which contains this code

The first URL pattern is
path('admin/',admin.site.urls). This pattern maps the URLadmin/to the Django admin interface. When a user accesses this URL, the admin interface will be displayed.The second URL pattern is
path('', include('main.urls')). This pattern maps the root URL (empty string) to the URLs defined in themain.urlsmodule. Theincludefunction is used to include the URL patterns from another module (main.urls) into the current URL configuration. This allows for modular and reusable URL patterns.
This is how we can render anything locally.



