<aside> 💡 코딩 컨벤션을 정의합니다

</aside>


1. Python 스타일

1-1 Naming (이름짓기)

# NO
def getUniqueVoters():
    pass

# YES
def get_unique_voters():
    pass
# NO
class blog_writer:
    pass

# YES
class BlogWriter:
    pass
class BookManager(models.Manager):
    def create_book(self, title):
        book = self.create(title=title)
        # do something with the book
        return book

class Book(models.Model):
    title = models.CharField(max_length=100)

    objects = BookManager()

book = Book.objects.create_book("Pride and Prejudice")
from django.db import models

class Book(models.Model):
    title = models.CharField(max_length=100)

    @classmethod
    def create(cls, title):
        book = cls(title=title)
        # do something with the book
        return book

book = Book.create("Pride and Prejudice")

2. Import

2.1 Import Group 작성 순서

  1. Standard libraries
  2. Third-party libraries
  3. Django components : Absolute imports
  4. Local Django components : (Explicit) Relative imports
  5. try/excepts
# future
from __future__ import unicode_literals

# 1. Standard libraries
import json
from itertools import chain

# 2. Third-party libraries
import bcrypt

# 3. Django components
from django.http import Http404
from django.http.response import (
    Http404, HttpResponse, HttpResponseNotAllowed, StreamingHttpResponse,
    cookie,
)

# 4. Local Django components
from .models import LogEntry

# 5. try/excepts
try:
    import yaml
except ImportError:
    yaml = None

CONSTANT = 'foo'

class Example(object):
    # ...

2.2 Indentation / Blank Line (들여쓰기 / 줄 공백)

<Indentation>

from django.http.response import (
    Http404, HttpResponse, HttpResponseNotAllowed, StreamingHttpResponse,# Line Breaking 후 공백 4개로 들여쓰기
    cookie,# 마지막 Import 뒤에도 Comma 포함
)# 닫는 괄호가 있는 줄에는 괄호만 존재

<Blank Line>

import requests
import json
# --------- 1줄 공백
from django.http.response import (
  Http404, HttpResponse, HttpResponseNotAllowed, StreamingHttpResponse,
  cookie,
)
# --------- 2줄 공백
# --------- 2줄 공백
class Example:
    pass

3. Templates

3.1 Spaces

<!-- NO -->
{{var}}
{{  var  }}

<!-- YES -->
{{ var }}

4. View

4-1. Request Parameter

# NO
def my_view(req, foo):
    pass

# YES
def my_view(request, foo):
    pass

5. Model