1/13
By default django doesn’t create a urls.py file in django app folder, so we need to do that manually
2/13
Now that we have created our app and linked it to our project
We can create the location and content of our page
Lets go to views.py for the content
5/13
Now we need to make sure Django can find the content
So we need to give it a location
Go to the file in the app folder called urls.py and write the following code
6/13
code in urls.py file in the Django app
The first line imports ‘path’ to make use of url links
From views we get the content of the page:
From django.urls import path
From .views import homePageView
urlpatterns = [
path(‘’, homePageView, name = ‘home’)
]
7/13
Finally we need to link the url of our Django app to our django project
head over to the urls.py file in our project
Here we need to tell Django that there are urls inside our app
8/13
See what happens when a users sends a request, its handled by django and it first checks the urls.py file in the project.
It will then find that in our code there is a reference to our app and then goes to the https://t.co/BhPyFVsV8T file in the app
9/13
We can do this by including the following code
We need the include function from django, so we will import include
Then we will use include in our path to tell django to include the urls in the django app
11/13
That’s it
We’ve created our homepage, configured the location and defined the content. #100DaysOfCode
12/13
The url path has 3 components 1. The first part defines if the url needs an additional name after the forward slash - path('',
13/13
2. A reference to the specific view for this page - homePageView, 3. An optional name that we can use inside our html pages to refer to this url pattern - name = 'home')
• • •
Missing some Tweet in this thread? You can try to
force a refresh
1/ 19 Variables are used to store information, so that they can be used later on in your code.
In Python a ‘string’ is text and a ‘integer’ or ‘float’ is a number
‘car_brand’ and ‘brand_type’ are variables in the example below
Variables can be stored inside other variables
2/19
No special signs are allowed to be used in the name of variables, except for ‘_’ like.
Numbers are allowed in the name of a variable, but not at the start
So ‘1car’ is not OK and ‘car1’ is OK.