[python][Django] Django Workflow and Architecture 장고 개발 워크플로우 및 구조

장고란?

 

Django는 Python으로 작성된 무료 오픈 소스 웹 애플리케이션 프레임워크입니다. 프레임워크는 개발을 더 쉽게 만드는 모듈 그룹에 지나지 않습니다. 그것들은 함께 정렬되며 처음부터가 아니라 관련 기존 공급품에서 응용 프로그램이나 웹 사이트를 만들 수 있습니다.

웹 사이트를 구축할 때 사용자 인증 처리 방법(가입, 로그인, 수화 아웃), 웹 사이트 관리 패널, 양식, 파일 전송 방법 등 대부분 동일한 구성 요소 집합을 원합니다.

프레임워크는 많은 사람들이 바퀴를 재발명하지 않아도 되도록 하고 대체 웹사이트를 구축하고 Django 프레임워크가 그 중 하나일 때 많은 오버헤드를 완화하는 데 도움을 주기 위해 존재합니다.

공식 프로젝트 웹 사이트는 Django를 "빠른 개발과 깨끗하고 실용적인 스타일을 장려하는 고급 Python 네트워크 프레임워크"라고 설명합니다. 네트워크 개발에 많은 노력을 기울이므로 바퀴를 재발명할 필요 없이 앱 작성을 목표로 삼을 수 있습니다. 무료이며 공개적으로 공급됩니다.”

Django는 스스로 사용할 수 있는 다양한 모듈을 제공합니다. 기본적으로 프레임워크는 많은 개발자의 시간 낭비와 골칫거리를 줄이기 위해 존재하며 Django도 완전히 다르지 않습니다.

장고 아키텍처

 

Django는 아키텍처용 MVT 프레임워크를 따릅니다.

  • M은 모델을 의미합니다.
  • V는 보기를 나타냅니다.
  • T는 템플릿을 의미합니다.

MVT는 일반적으로 모델, 보기 및 컨트롤러인 MVC와 매우 유사합니다. 여기서 MVC와 MVT의 차이점은 Django 자체가 MVC 설계 내에서 컨트롤러 절반이 수행하는 작업을 수행한다는 것입니다. Django는 희생 템플릿을 통해 컨트롤러의 이 작업을 수행합니다. 정확하게는 템플릿 파일은 하이퍼텍스트 마크업 언어 절반과 함께 DTL이라고 하는 Django 예제 언어가 혼합된 것일 수 있습니다.

디장고Django 아키텍처의 이점

 

Django 프레임워크는 이 디자인을 기반으로 하며 복잡한 코드를 작성할 필요 없이 이 세 가지 요소 간에 실제로 통신합니다. 이것이 Django가 품질을 얻고 있는 이유입니다.

이 Django 디자인에는 다음과 같은 수많은 이점이 있습니다.

1. 신속한 개발 t:

서로 다른 구성 요소로 분리되는 Django 디자인을 통해 여러 개발자가 동일한 애플리케이션의 서로 다른 측면에서 동시에 작업하기가 쉽습니다. 그것은 또한 Django의 옵션 중 하나입니다.

2. 느슨하게 결합됨 :

Django는 응용 프로그램의 바인딩 요소에서 매 순간 서로를 필요로 하는 완전히 다른 요소를 가지고 있어 일반 웹 사이트의 안전성을 높일 수 있습니다. 모델 파일은 현재 웹 페이지에 저장하는 대신 저희 서버에만 저장할 수 있기 때문입니다.

3. 수정 용이성:

Django 디자인에는 완전히 다른 요소의 단위가 있기 때문에 이것은 개발의 중요한 사실이 될 수 있습니다. 많은 요소에 수정이 있으면 대체 요소에서 수정하지 않는 경향이 있습니다. 이것은 실제로 Django의 특별한 옵션 중 하나일 수 있습니다. 여기에서 대체 프레임워크보다 더 많은 웹 사이트 기능을 제공하는 방법을 제공하기 때문입니다.

4. 보안:

고급 인터넷 애플리케이션을 구축할 때 보안은 반영해야 할 정말 중요한 측면이 됩니다. Django는 이러한 우려를 이해하고 귀하의 노력을 낭비하지 않도록 최선의 방어자를 제공합니다. 클릭 재킹, 교차 사이트 스크립팅 및 SQL 주입을 사용하여 Django는 애플리케이션의 안전을 위한 견고한 벽을 구축합니다. 사용자 인증은 Django가 제공하는 사용자 계정과 암호를 안전하게 관리하기 위한 중요한 기능입니다.

5. 확장 가능:

확장성은 플랫폼의 크기나 볼륨이 증가할 때 애플리케이션이 잘 작동하는 능력으로 이해될 수 있습니다. Django는 이 문제 중에 쉽게 작동합니다. Django로 만든 웹사이트는 한 번에 여러 사용자를 처리할 수 있는 기능이 있습니다. 인기 있는 일부 웹사이트 피해 Django는 Spotify, Netflix, YouTube, Mozilla, Quora 등을 구현합니다.

Django에서 새 프로젝트 만들기

 

새 Django 프로젝트를 시작하려면 아래 명령을 실행하십시오.

1
django-admin startproject myproject

위의 명령을 실행하면 Django 프로젝트의 기본 폴더 구조가 생성됩니다.

현재 myproject 디렉토리는 다음과 같습니다.

1
2
4
5
6
7
8
myproject/                  <-- higher level folder
 |-- myproject/             <-- django project folder
 |    |-- myproject/
 |    |    |-- __init__.py
 |    |    |-- settings.py
 |    |    |-- urls.py
 |    |    |-- wsgi.py
 |    +-- manage.py
  • manage.py : django-admin 명령줄 유틸리티를 사용하기 위한 바로 가기입니다 . 프로젝트와 관련된 관리 명령을 실행하는 데 사용됩니다. 이를 사용하여 개발 서버를 실행하고, 테스트를 실행하고, 마이그레이션을 생성하는 등의 작업을 수행합니다.
  • __init__.py : 이 빈 파일은 Python에게 이 폴더가 Python 패키지임을 알려줍니다.
  • settings.py : 이 파일에는 모든 프로젝트 구성이 포함되어 있습니다. 우리는 항상 이 파일을 참조할 것입니다!
  • urls.py : 이 파일은 프로젝트의 경로 및 경로 매핑을 담당합니다. 예를 들어 URL /about/에 무언가를 표시하려면 먼저 여기에 매핑해야 합니다.
  • wsgi.py : 이 파일은 배포에 사용되는 간단한 게이트웨이 인터페이스입니다.

이제 모든 것이 설정되었으며 아래 명령을 사용하여 서버를 실행할 수 있습니다.

1
python manage.py runserver

이제 웹 브라우저에서 URL( http://127.0.0.1:8000 )을 열면 서버가 올바르게 실행되고 있음을 의미하는 성공 페이지가 표시됩니다.

Django 앱 만들기

 

Django 프로젝트에는 그 안에 많은 앱이 포함되어 있습니다. 앱은 프로젝트 없이 실행할 수 없습니다. 다음 명령으로 앱을 만들 수 있습니다.

1
django-admin startapp articles

그러면 다음과 같은 디렉토리 구조가 됩니다.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
myproject/
 |-- myproject/
 |    |-- articles/                <-- our new django app!
 |    |    |-- migrations/
 |    |    |    +-- __init__.py
 |    |    |-- __init__.py
 |    |    |-- admin.py
 |    |    |-- apps.py
 |    |    |-- models.py
 |    |    |-- tests.py
 |    |    +-- views.py
 |    |-- myproject/
 |    |    |-- __init__.py
 |    |    |-- settings.py
 |    |    |-- urls.py
 |    |    |-- wsgi.py
 |    +-- manage.py
 +-- venv

따라서 먼저 각 파일이 수행하는 작업을 살펴보겠습니다.

  • migrations : 여기서 Django는 py 파일 에서 생성한 변경 사항을 추적하고 데이터베이스와 models.py를 동기화된 상태로 유지하기 위해 일부 파일을 저장합니다.
  • admin.py : Django Admin 이라는 내장 Django 앱의 구성 파일입니다 .
  • apps.py : 앱 자체의 구성 파일입니다.
  • models.py : 웹 애플리케이션의 엔터티를 정의하는 곳입니다. 모델은 Django에 의해 데이터베이스 테이블로 자동 변환됩니다.
  • tests.py : 이 파일은 앱의 단위 테스트를 작성하는 데 사용됩니다.
  • views.py : 웹 애플리케이션의 요청/응답 주기를 처리하는 파일입니다.

이제 첫 번째 앱을 만들었으므로 이를 사용하도록 프로젝트를 구성해 보겠습니다. settings.py 파일을 열고 installed_apps 블록을 찾습니다 .

settings.py

1
2
4
5
6
7
8
9
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'Django.contrib.staticfiles',
‘articles’
]

여기에 설치된 앱 섹션에 '기사'를 추가했습니다. 이제 앱을 Django 프로젝트와 함께 실행할 준비가 되었습니다.

데이터베이스 구성

기본적으로 Django 프로젝트는 sqlite3 데이터베이스와 함께 제공되지만 요구 사항에 따라 MySQL 또는 Postgresql을 사용하도록 사용자 지정할 수 있습니다.

settings.py

01
02
03
04
05
06
07
08
09
10
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blog',
        'USER': 'postgres',
        'PASSWORD': '**********',
        'HOST': 'localhost',
        'PORT': 5432,
    }
}

이제 프로젝트가 Postgres 데이터베이스와 연결되었으며 실행할 준비가 되었습니다.

이제 데이터베이스 구성과 함께 MVT 패턴의 작동 방식과 Django 애플리케이션의 구조를 배웠습니다.

 

What Is Django?

Django is a free and open-source web application framework written in Python. A framework is nothing over a group of modules that create development easier. They’re sorted along, and permit you to make applications or websites from associated existing supplies, rather than from scratch.

When you are building a website, you mostly would like the same set of components: how to handle user authentication (signing up, signing in, sign language out), a management panel for your website, forms, how to transfer files, etc.

Frameworks exist to save lots of you from having to reinvent the wheel and to assist alleviate a number of the overhead once you’re building a replacement website and the Django framework is one of all them.

The official project website describes Django as “a high-level Python net framework that encourages fast development and clean, pragmatic style. It takes care of a lot of effort of net development, thus you’ll be able to target writing your app with no need to reinvent the wheel. It’s free and open supply.”

Django offers an enormous assortment of modules that you’ll be able to use on your own. Primarily, frameworks exist to save lots of developers tons of wasted time and headaches and Django isn’t any totally different.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

Django Architecture

Django follows the MVT framework for architecture.

  • M stands for Model
  • V stands for View
  • T stands for Template

MVT is generally very similar to that MVC which is a Model, View, and Controller. The distinction between MVC and MVT here is that Django itself will do the work done by the controller half within the MVC design. Django will do this work of the controller by victimization templates. Precisely, the template file may be a mixture of hypertext markup language half and Django example Language conjointly referred to as DTL.

DijangoBenefits Of Django Architecture

The Django Framework is predicated on this design and it really communicates between these 3 elements without having to put in writing complicated code. That’s why Django is gaining quality.

This design of Django has numerous blessings like:

1. Rapid Development:

Django design that separates in different components makes it easy for multiple developers to work on different aspects of the same application simultaneously. That’s additionally one among the options of Django.

2. Loosely Coupled:

Django has totally different elements that need one another at bound elements of the application, at each instant, that will increase the safety of the general website. Because the model file can currently solely save on our server instead of saving on the webpage.

3. Ease of Modification:

This can be a crucial fact of development as there is a unit of totally different elements in Django design. If there’s a modification in numerous elements, we tend not to modify it in alternative elements. This can be really one of the special options of Django, as here it provides us a way with more ability of our website than alternative frameworks.

4. Security:

When building high-end internet applications, security becomes a really crucial facet to reflect on. Django understands this concern and provides its best defender to avoid wasting your efforts. Using click-jacking, cross-site scripting, and SQL injections Django builds a robust wall for the application’s safety. User authentication is additionally a crucial feature to securely manage user accounts and passwords that Django provides.

5. Scalable:

Scalability can be understood as an ability of an application to work well when the size or volume of the platform increases. Django works effortlessly during this issue. Websites created with Django have the capability to handle multiple users at one time. Some well-liked websites victimization Django embody Spotify, Netflix, YouTube, Mozilla, Quora, etc.

Creating A New Project In Django

To start a new Django project, run the command below:

1
django-admin startproject myproject

After we run the command above, it will generate the base folder structure for a Django project.

Right now, our myproject directory looks like this:

1
2
3
4
5
6
7
8
myproject/                  <-- higher level folder
 |-- myproject/             <-- django project folder
 |    |-- myproject/
 |    |    |-- __init__.py
 |    |    |-- settings.py
 |    |    |-- urls.py
 |    |    |-- wsgi.py
 |    +-- manage.py
  • manage.py: a shortcut to use the django-admin command-line utility. It’s used to run management commands related to our project. We will use it to run the development server, run tests, create migrations, and much more.
  • __init__.py: this empty file tells Python that this folder is a Python package.
  • settings.py: this file contains all the project’s configurations. We will refer to this file all the time!
  • urls.py: this file is responsible for mapping the routes and paths in our project. For example, if you want to show something in the URL /about/, you have to map it here first.
  • wsgi.py: this file is a simple gateway interface used for deployment.

Now everything is set up and we can run the server using the below command

1
python manage.py runserver

Now open the URL in a Web browser: http://127.0.0.1:8000 and you should see the success page, which means the server is running correctly.

Creating Django Apps

Django project contains many apps within it. An app can’t run without a project. You can create app by the following command

1
django-admin startapp articles

This will give us the following directory structure:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
myproject/
 |-- myproject/
 |    |-- articles/                <-- our new django app!
 |    |    |-- migrations/
 |    |    |    +-- __init__.py
 |    |    |-- __init__.py
 |    |    |-- admin.py
 |    |    |-- apps.py
 |    |    |-- models.py
 |    |    |-- tests.py
 |    |    +-- views.py
 |    |-- myproject/
 |    |    |-- __init__.py
 |    |    |-- settings.py
 |    |    |-- urls.py
 |    |    |-- wsgi.py
 |    +-- manage.py
 +-- venv

So, let’s first explore what each file does:

  • migrations: here Django stores some files to keep track of the changes you create in the py file, and to keep the database and the models.py synchronized.
  • admin.py: this is a configuration file for a built-in Django app called Django Admin.
  • apps.py: this is a configuration file of the app itself.
  • models.py: here is where we define the entities of our Web application. The models are translated automatically by Django into database tables.
  • tests.py: this file is used to write unit tests for the app.
  • views.py: this is the file where we handle the request/response cycle of our Web application.

Now that we created our first app, let’s configure our project to use it. Open settings.py file and find installed_apps block.

settings.py

1
2
3
4
5
6
7
8
9
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'Django.contrib.staticfiles',
‘articles’
]

Here we have added ‘articles’ in the installed apps section. Now the app is ready to run with the Django project.

Configuring Database

By default Django project comes with sqlite3 database but you can customize it to use MySQL or Postgresql as per the requirements.

settings.py

01
02
03
04
05
06
07
08
09
10
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blog',
        'USER': 'postgres',
        'PASSWORD': '**********',
        'HOST': 'localhost',
        'PORT': 5432,
    }
}

Now your project is connected with Postgres database and ready to run.

So now, we have learned how the MVT pattern works and the structure of the Django application along with the database configuration.

----------------------------------------

[출처] https://www.andolasoft.com/blog/django-workflow-and-architecture.html

 

 

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
452 [Python 인터넷] 7 - 개요 file 졸리운_곰 2023.03.30 3
451 [Python 인터넷] 6 - href 연결하기 file 졸리운_곰 2023.03.26 5
450 [Python 인터넷] 5 - 다른 페이지 크롤링 file 졸리운_곰 2023.03.26 9
449 [Python 인터넷] 4 - flask에 css 적용하기 file 졸리운_곰 2023.03.26 7
448 [Python 인터넷] 3 - 크롤링한 데이터 html에 보여주기 file 졸리운_곰 2023.03.26 4
447 [Python 인터넷] 2 - flask 프로젝트 생성, 세팅 file 졸리운_곰 2023.03.26 4
446 [Python 인터넷] 1 - 트렌드 홈페이지 개발 개요 file 졸리운_곰 2023.03.26 5
445 [python][자료구조] [Python] Logging to MongoDB (로그 남기기) file 졸리운_곰 2023.03.24 3
444 [Python 인터넷] Python Python - 파이썬 REST API 통신 예제(POST 요청하기, 서버만들기) file 졸리운_곰 2023.03.21 4
443 [python][Django] Python Package Trends: Visualize Package Download Stats in Django file 졸리운_곰 2023.03.18 14
442 [Python 데이터분석] [Python 환경설정] VS code 설치 및 Anaconda와 연동하기 file 졸리운_곰 2023.03.17 6
441 [Python 일반] 파이썬에서 프로그램 일시중지하는 세가지 방법 How to Pause in python 졸리운_곰 2023.03.17 22
» [python][Django] Django Workflow and Architecture 장고 개발 워크플로우 및 구조 file 졸리운_곰 2023.03.12 1
439 [python][Django] DRF(장고 rest framework)와 REST API서버 개발 file 졸리운_곰 2023.03.12 15
438 [python][자료구조] [스파르타 웹 개발 종합] 파이썬으로 크롤링하고 DB에 저장하기(request, bs4, mongoDB 패키지 사용) 졸리운_곰 2023.03.12 2
437 [Python 인터넷] Using a Python HTTP Proxy Server to Simulate an API Gateway file 졸리운_곰 2023.03.11 23
436 [python][Django] [개념] Django는 Web Server가 아니라구요!! file 졸리운_곰 2023.03.11 57
435 [python][Django] [Django] Django Rest Framework에서 request 로깅하기 졸리운_곰 2023.03.11 1
434 [python][Django] Django REST Framework 졸리운_곰 2023.03.10 7
433 [python][Django] Django의 기본 개념 file 졸리운_곰 2023.03.10 3
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED