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 👇
1/11
Terminal

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
2/11
Navigate in the terminal to the folder of our django project which we created last time and run the virtual environment
3/11
Type the following command to create an app

If you get confused, remember: create the app in the same folder where the ‘manage.py’ file is

Python https://t.co/k0cX6DJlc7 startapp razahome

#Django Image
4/11

This creates the following structure in our django project

1. Admin.py is a settings file for the built- django admin app
2. apps.py is a settings file for the app itself

continued 👇 Image
5/11

3. Migrations - this folder keeps track of any Changes to our models.py, which is our datamodel and database

4. Models.py is where we define our database models which Django translates in database tables
6/11

5. Test.py is for the app specific tests

6. Views.py is where we take the request/response for our web app and reply with the content of the page
7/11
Django is structured in the following way

A user types a link in the browser
The url tells django the location of the django app
the view file tells django what the content of the page is

The model gives the data
and the template gives the structure and style of the page Image
8/11

Simplified:
User -> URL - > View -> Model(usually if data is involved) -> Template
9/11

This structure can also guide us how to build the app and how write our code

First we need to link the app to the project.
10/11

Go to the project folder and open the settings.py file

Every time we create an app, we need to include it in the https://t.co/7VnJZDvcP1 file to make sure Django knows this app exists

There is a standard convention for this

appname.apps.AppnameConfig Image
11/11

So in our case ‘razahome.apps.RazahomeConfig’,

Now that our app is registraties we can build our django app or web page

In the next thread we will configure the urls.py file and views.py to create the location and content of our django app

• • •

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!

PDF

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

25 May
👇🧵
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 ☺️

thanks!🙏🙏🙏
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

#100DaysOfCode
Read 14 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
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.
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!

:(