After creating our #Django app

Let's create and fill in the urls.py and views.py files

ps please follow if you like this thread ☺️

By default django doesn’t create a urls.py file in django app folder, so we need to do that manually
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

Remember django has a lot pre-configured.

So we can use built in classes and functions without having to reinvent the weel ourself

This function accepts the request from the user and returns a response, in this case, Hello World

the code in views.py

from django.http import HttpResponse

def homePageView(request):
return HttpResponse(‘Hello World’)
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
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’)
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
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
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
code in urls.py in the django project

From django.contrib import admin
From django.urls import path, include

Urlpatterns = [
path(‘admin/‘, admin.site.urls),
That’s it
We’ve created our homepage, configured the location and defined the content.
The url path has 3 components
1. The first part defines if the url needs an additional name after the forward slash - path('',

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

Keep Current with Raza Zaidi

Raza Zaidi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @razacodes

21 May
Last thread🧵 we created a django project

And went over the basic structure of a website and the files

In this thread we will create a django app

would me the world if you could retweet or like this thread🙏🙏🙏

What we covered so far 👇

Navigate to our folder: Cd project

Create a project folder: Mkdir my project

Create virtual environment: Python -m venv ./myvenv

Install django - pip install Django

Create django project - Django-admin startproject myfirstproject
Navigate in the terminal to the folder of our django project which we created last time and run the virtual environment
Read 12 tweets
14 May
Beginning a thread🧵 about the basics in #Python you need to know for #Django👇

Django is a #webframework to build interactive #websites for Python and is great for fast #development
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
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.
Read 22 tweets

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!