Printing "Hello World" using Python Django Web Framework
Published: 2021-09-06 05:53:12

Django is a python framework used for making web apps. If you don't have any idea about using Django frame work, I'm going to teach you a simple command using Django, so let's get started!!


I. Install requirements

On your command line, type "pip install django" if you are using windows. If you are using Linux, installing it is a bit different. To install this on your Linux, open your terminal and type "pip3 install django".

![installing django](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5bwuolhj1spgbu1k1hb.png)

Since I've already installed it, it says "requirement already satisfied"


II. Make your project and your app

In Django, project and app are different from each other. Django apps are the those who contains characteristics and features of you web app. On another hand, Django projects are the compiler of the Django apps. It may contain one or more apps and apps can contain one or more features. You must create your project first before your app.


To make a project, select a directory first where you want to your local django project. After selecting one on your cmd/terminal, type "django-admin startproject myProject"

![making project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkstn63u3uhlmdfy4y8v.png)

"myProject" is the name of our Django project. Inside the "myProject" directory, you can see another "myProject" directory and that is our project. It also contains "db.sqlite3" which is our database & "manage.py" which we will use to control our Django project.

To make an app, inside the first "myProject" directory, type "python manage.py startapp Myapp". But since I am using linux, I'm going to use "python3 manage.py startapp myApp"

![making app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gftmg1exz57y2olx4lcw.png)

"myApp" is the name of our django app.

Now, your app should look like this:
![django structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4o6gb2pqxrxinsqrbmwq.png)


III. Connecting our app to our project

We need to connect our app on our project to access our app directory, "myApps". To do this, head to "myPrjoect/settings.py", then find the list of "INSTALLED_APPS". List there your app by typing "myApp.apps.MyappConfig"

![installed apps in settings.py](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kkcqkvupm7hf8fv9tqd.png)

"MyappConfig" is a class in apps.py which is located in "myApp" directory means "myApp.apps.MyappConfig" is a path to "MyappConfig". Now, we can access everything on our app.

To access the app, we need to connect our "myProject" to our "myApp" using the urls.py. 
In our "myProject/urls.py", next to other imports, type:
    from myApp import views

After it head to urlpatterns and type: path('', views.home, name = "home")

By the way, the format for urlpattern is:
 path('link', views.function/class views, name='name')

This urlpattern is just one of many ways to do this work but this is one of the easiest way.

Now, our "urls.py" should look like this:
![what url should looks like](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf2t6f7wedcw8y6a1ddc.png)

IV. Modify the app views
Now the final step is to make some modification in our myApp/views.py. In views.py, type "from django.http import HttpResponse"

  Then type:
![home()](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53lacbgql4a34pfhrugy.png)



V. Testing our code
We want to know it this is working so head to the terminal again and type "python manage.py runserver" if you are using windows but I'm on Linux so I'm going to use "python3" instead of python. 
After running, it should look like this:
![runserver](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qf364mtj9u4b3iswgg8h.png)

To see it in browser "CRTL" + "Left Click" link and it will direct you to your browser. And it should look like this:
![httpResponse](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ao491viix8nzomf5jzbr.png)