Django(1)

77raina·2020년 5월 7일
1

What is Django?

It is a python web framework, which does not allow us to customize that much and mostly inherited. Templates are given but are not actually needed but rather models, views, and control(logics) are needed! What we're going to make is endpoint, api, data offering api service.

Backend developer's Requirements

  1. API Design

How to start project?

$ conda create -n test03 python=3.8
$ conda env list 

It shows a list of virtual environments

$ conda activate test03
$ pip freeze

To see the packages installed in the virtual environment

$ pip install django
$ mkdir practice 

It creates a practice app

$ django-admin startproject test03
$ tree

Below is the directory tree when we start project test03

.
├── manage.py
└── test03
    ├── __init__.py
    ├── asgi.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

manage.py is the highest directory of the project.
asgi.py is an asynchronous server gate interface.
wsgi.py is used to connect web server and django framework
urls.py is for server routing.

Quick Summary for Django Cycle Flow

  1. User as a client requests to see the web application.
  2. Requesting a specific address and it breaks down into small pieces, which is called parcing.
  3. Broken down addresses are distributed in view depending on their roles.
  4. Views.py has a written code by us for developing each web application's functionality
  5. Then it's delivered to template.
  6. User receives a response and client is able to see in the browser.
$ python manage.py runserver
$ python manage.py startapp account
├── account
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── db.sqlite3
├── manage.py
└── test03
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-38.pyc
    │   ├── settings.cpython-38.pyc
    │   ├── urls.cpython-38.pyc
    │   └── wsgi.cpython-38.pyc
    ├── asgi.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

App vs. Project?

App is a web application for web log system, publicly recorded database, or opinion polls in a small scale, whereas project is a collection of certain website config and apps. Project can contain multiples of apps. An app can be in multiples of projects.

$ python manage.py makemigrations account 

It'll create migrations for 'account'

Migration: Intermediate process to check the history of change in models.py. If there's an mistake found after the database modification, we can't go edit the database, but should modify in models.py. It's basically acting like a git.

$ python manage.py sqlmigrate account 0001 

It'll show sql queries

$ python manage.py migrate account 0001
profile
Backend Developer

0개의 댓글