DEV Community

Cover image for Today I learn Django #2
Ferry
Ferry

Posted on • Updated on

Today I learn Django #2

Today I create a Django project and an app inside it. If you haven't seen my first note please kindly do.

 

Btw, I skip the Django installation method, but basically when I created something with python, firstly I create a virtual environment and then install the package that I need. This time Django package.

OK... Today, I created a project called wisdompets using
django-admin startproject wisdompets.

 

After executing that syntax, Django creates a new folder with wisdompets as the name. Inside the folder, there is a folder with the same name that contains file .py.
wisdompets_folder_as_project_folder

The explanation

File Name Role
manage.py Runs command for the project
__init__.py Tell python the folder contains python code
wsgi.py & asgi.py Files needed to connect to the live server
settings.py Configure the Django project
urls.py Routes web requests based on URL

 

For __pychache__ folder and db.sqlite3 all I know is the files are generated after I run Django for the first time using python manage.py runserver syntax in the terminal.

 

The picture shown below is what I get after running the runserver syntax.
Django run successfully

 

Interesting... Like I said in my first note about Django. Django project can has a couple of apps. But what is that mean? I confused before what is the meaning of a couple of apps. Because what I know is the project = app (read: the project is the same as an app. But I wrong. Apparently, what is meant like this, a web can have a blog, forum, or wiki inside it. This is what they call an app(blog, forum, etc). After knowing this I go like "Aaaah, I see know~".

 

To create an app with adoptions as a name, I need to run

python manage.py startapp adoptions.

Again, the syntax will automatically generate a new folder with the app name. Look the picture bellow.
Django app's files

Folder and File's Name Role
admin.py Define administrative interface for the app that will allow us to see and edit the data related to the application
apps.py Control settings specific for app
models.py Provide data layer used by Django to create database schema and queries
test.py Used to write unit test for app functionality
views.py Defines the logic and control flow for handling requests and defines the HTTP responses that are returned
migrations/ Folder that contains files used by Django do migrate database

Seem to much right? Agreed. Right now when I write this note, I still don't know much what that many files exactly do. Only the explanation that I know. As I continue to adventure, I will gradually level up.

Cover image -> Technology vector created by grmarc - www.freepik.com

Top comments (0)