Skip to main content

Django Project Tour

In this tutorial, we’re going to take a look on each file that exists in our django project folder.

Let’s say, we’ve created a project named as my_website on our desktop. Now open that folder you can see another folder (directory) with the same name inside our project folder.

Django Project Tour 1

Along with this directory, we’ve other two files db.sqllite3 and manage.py.

Let’s understand these files.

manage.py

This is the file that we’ve used to run server. Basically that manage.py file help us to do some top level admin things. To see all the funtionality of that file other than running a server, just open terminal or command prompt and navigate to the directory where our manage.py file exists and run the command below.

python3 manage.py help

or

python manage.py help  (if you have only python3 installed in your system)

Now after running this command you can actually see all the things that our manage.py file can do like startapp, runserver, collectstatic. We’ll use many of these things later and we should never edit this file if you’re editing this file for specific reason, at that point you should be an expert django user before you go messing up with this file.

db.sqlite3

This file is a database that is generated for us whenever we make a new project and run the server. This is going to be a non-human readable file. It’s supposed to store data in a really efficient way.

Now open my_website directory inside our project folder and you’ll see some other files and a directory as shown below.

Django Project Tour 2

__pycache_

This directory is going to be auto-generated everytime when we’re running the server. Inside __pycache_ there are some other files having extension .pyc. These are some internal files, we doesn’t need to worry about these at all.

__init__.py

This is also created automatically whenever we initially create a new project and we’ll never touch this file too because this file is not there for programmer’s use. It is there for some internal django working. We’re not going to worry about it too.

settings.py

This is the file, that we’re going to use a lot. If we open this file using any text editor then you can see that there is a BASE_DIR variable that have the path of our base directory of our project.

Django Project Tour 3

Next there is a SECRET_KEY that we should never show to anybody if we’re going to pushing up our project to internet. We can also change this key as we want to.

Django Project Tour 4

Next is DEBUG, that is set as True. This is basically saying that you are working in a development environment on your computer. This helps us to show errors while running our project. When our project will be live on the internet, we’ll set DEBUG as False.

Next two variables are ALLOWED_HOSTS and INSTALLED_APPS that we’ll see later when our project will be under production phase.

Next is MIDDLEWARE, This is also some advance stuff and auto-generated code by django.

Django Project Tour 5

Then there is a ROOT_URLCONF variable that’s basically saying where your initial URL file is.

Django Project Tour 6

Next one is TEMPELATES, basically these tempelates helps to turning the python code into HTML, because when someone requests a website, it is going to give back HTML. As we can see when we open page source of any webpage, It gives us bunch of HTML Tags.

Django Project Tour 7

Next is WSGI_APPLICATION, This is used when we’re hosting our project live, how people connect with it. We’ll see more when we publish our project live to the internet.

Django Project Tour 8

Next is DATABASES, This is the code that generated that file named as db.sqlite3 in our project directory. If we want to create another database file then we can also generate by editing this code.

Django Project Tour 9

Next is AUTH_PASSWORD_VALIDATORS, This basically saying that whenever someone makes a new user account what sort of things do we want to require of to get their passwords we’ll see it later too.

Django Project Tour 10

Now other variables like LANGUAGE_CODE, TIME_ZONE are just there for making our website unique like what language code we want to use, by default it is US-English and what Time-zone we want to use.

urls.py

Anytime someone visits our website that is s connected to our django project. It’s going to come into this file and this file decides where the user’s requests should go next and what HTML is to sent back to user.

Django Project Tour 11

wsgi.py

This file is for hosting our website so other people can access it, we’ll see this file when we upload our project to a server.

Django Project Tour 12

So I hope you have understood that what the files inside our project folder are and what are the uses of those files.

If you have any confusion related to this tutorial, then please let us know in comments.

The post Django Project Tour appeared first on The Crazy Programmer.



from The Crazy Programmer https://www.thecrazyprogrammer.com/2018/09/django-project-tour.html

Comments

Popular posts from this blog

dotnet sdk list and dotnet sdk latest

Can someone make .NET Core better with a simple global command? Fanie Reynders did and he did it in a simple and elegant way. I'm envious, in fact, because I spec'ed this exact thing out in a meeting a few months ago but I could have just done it like he did and I would have used fewer keystrokes! Last year when .NET Core was just getting started, there was a "DNVM" helper command that you could use to simplify dealing with multiple versions of the .NET SDK on one machine. Later, rather than 'switching global SDK versions,' switching was simplified to be handled on a folder by folder basis. That meant that if you had a project in a folder with no global.json that pinned the SDK version, your project would use the latest installed version. If you liked, you could create a global.json file and pin your project's folder to a specific version. Great, but I would constantly have to google to remember the format for the global.json file, and I'd constan...

Rail Fence Cipher Program in C and C++[Encryption & Decryption]

Here you will get rail fence cipher program in C and C++ for encryption and decryption. It is a kind of transposition cipher which is also known as zigzag cipher. Below is an example. Here Key = 3. For encryption we write the message diagonally in zigzag form in a matrix having total rows = key and total columns = message length. Then read the matrix row wise horizontally to get encrypted message. Rail Fence Cipher Program in C #include<stdio.h> #include<string.h> void encryptMsg(char msg[], int key){ int msgLen = strlen(msg), i, j, k = -1, row = 0, col = 0; char railMatrix[key][msgLen]; for(i = 0; i < key; ++i) for(j = 0; j < msgLen; ++j) railMatrix[i][j] = '\n'; for(i = 0; i < msgLen; ++i){ railMatrix[row][col++] = msg[i]; if(row == 0 || row == key-1) k= k * (-1); row = row + k; } printf("\nEncrypted Message: "); for(i = 0; i < key; ++i) f...

Data Encryption Standard (DES) Algorithm

Data Encryption Standard is a symmetric-key algorithm for the encrypting the data. It comes under block cipher algorithm which follows Feistel structure. Here is the block diagram of Data Encryption Standard. Fig1: DES Algorithm Block Diagram [Image Source: Cryptography and Network Security Principles and Practices 4 th Ed by William Stallings] Explanation for above diagram: Each character of plain text converted into binary format. Every time we take 64 bits from that and give as input to DES algorithm, then it processed through 16 rounds and then converted to cipher text. Initial Permutation: 64 bit plain text goes under initial permutation and then given to round 1. Since initial permutation step receiving 64 bits, it contains an 1×64 matrix which contains numbers from 1 to 64 but in shuffled order. After that, we arrange our original 64 bit text in the order mentioned in that matrix. [You can see the matrix in below code] After initial permutation, 64 bit text passed throug...