This is the first video in this course that will teach you about Django. In this video, 2
we are going to create a very simple Django project to display Hello World 3
Okay Let’s start, open a commend prompt and create a new project by typing Django-admin 4
startproject and the name of the project. In this case, the name of my project is first_project. 5
After create a new project, Django will create a directory with the same name as our project. 6
Let’s try to dir, here we can see that we have first_project directory. Let’s cd to 7
this directory 8
Next, we need to create a Django app by typing python manage.py and the name of app, in this 9
case, the name of my app is app1 10
When we create an app in Django, Django will also automatically create a directory with 11
the same name as the app for us. Let’s try to dir, here we can see that we have app1 directory 12
Now let’s open our code editor. If you use visual studio code, you can simply type code 13
space dot and the visual studio code will open in the current directory. 14
Here we can see our first_project. You can see that we have a lot of file in here 15
All of this file is automatically generated by Django 16
Let’s try to run our project. Open the command prompt and type python manage.py runserver. 17
We will see warning that you have some unplied migrations like this, but for now, we can 18
ignore it, we will discuss about that later in the next video 19
Here we can see that our server is running on 127.0.0.1:8000. Let’s open our browser 20
and go to 127.0.0.1:8000. 21
Here we get the default display of Django 22
this is mean that our project is running successfully. 23
Now let’s try to manimpulate our project to display hello world. Open a visual studio code. 24
First thing that we have to do is register our new app, which is app1. We can register 25
it on settings.py. Here in the INSTALLED_APPS, let’s add our new app. 26
Next let’s edit urls.py file, here we can remove the comment so we can read the important 27
script easily. Let’s add a new path here, we will use root url here, and include app1.urls, 28
means that the root url will read for urls.py file inside app1. 29
Next, if we see here, inside app1 directory, we don’t have urls.py file, so we need to created it first. 30
We can just copy paste the urls script from the urls.py file inside first_project directory 31
Oh ya, if we see here, we use an include keyword, so we need to import it first. 32
In the urls.py inside app1 directory, we don’t need admin, so we can delete it. We also need 33
to delete this line. 34
Here, I will create a new path hello_world. Here we can replace the include with views.hello_world. 35
This script mean, if we go to hello_world url, we will redirected to the hello_world 36
function inside views.py 37
Here we can see that we have views.py file, later we will create hello_world function 38
inside this file. But before that, we need to import views In here, because we use it here 39
Now let’s create hello_world function in views.py, 40
here we need to add an argument request 41
in this video, we will just return simple html expressions, so we need to import httpresponse 42
from Django.shortcuts. Next, inside hello_world function, we need to return a simple html 43
tag using httpresponse, in this case I will just return “Selamat datang di Django” 44
with H1 tag. Selamat datang di Django is “Welcome to Django” in Indonesian. 45
Okay we have done here, let’s take a look at command prompt, make sure that we don’t 46
have any error. Okay we don’t have any error here. Let’s go to our browser and navigate 47
to 127.0.0.1:8000/hello_world. Here we can see that we get “Selamat Datang di Django”. 48
Now let’s try to remove hello_world from url and see what happened. We will see 404 eror here 49
Why? let’s go back to visual studio code and open urls.py inside first_project, 50
here we can see that the root url is point to urls.py inside app1, and if we see the 51
urls.py inside app1, here we don’t have a root url, we just have hello_world url. 52
That’s why if we remove hello_world from our browser, we will get 404 error. 53
Now let's try to remove hello_world url here. 54
Back to browser and refresh. Okey, now we can see “Selamat datang di Django” in 55
root url. But if we try to put hello_world again in the url, we will absolutely get 404 56
error, that is because we don’t have hello_world url. 57
May be you will be little confuse about the url, but don’t worry, we will cover about 58
url deeply in the next video. 59
I hope you understand about this basic concept of Django. I recommend you to re watch this 60
video if you don’t really understand about the basic concept of Django. 61
And if you have any further questions, feel free to ask me and I will do my best to answer all of your question 62
Thankyou for watching and See you on the next video.