Python
-
[django] RedirectView, redirect in urls.pyPython/초간단 장고 Django 2022. 9. 9. 00:42
board.urls을 2번 인클루드하면 경고가 발생합니다. from django.contrib import admin from django.urls import path, include urlpatterns = [ path('', include('board.urls')), path('board/', include('board.urls')), path('admin/', admin.site.urls), ] WARNINGS: ?: (urls.W005) URL namespace 'board' isn't unique. You may not be able to reverse all URLs in this namespace 이 상황에서 redirect를 만나면 라우팅이 엉망이 되죠. 그땐 경고가 아닌 에러가 발생합니..
-
django as.view() 그리고 dispatch()Python/초간단 장고 Django 2022. 9. 7. 23:59
https://docs.djangoproject.com/en/4.1/ref/class-based-views/base/ Base views | Django documentation | Django Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate docs.djangoproject.com 클래스 뷰의 작동은 위 링크에 잘 설명되어 있습니다. urls.py에 등록된 view class는 아래와 같이 작동합니다. response = MyView.as_view()(request) as.view()가 진입점이 되죠. 진입 후에는..
-
django {% with %}Python/초간단 장고 Django 2022. 9. 7. 23:17
https://docs.djangoproject.com/en/4.1/ref/templates/builtins/#with Built-in template tags and filters | Django documentation | Django Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate docs.djangoproject.com Caches a complex variable under a simpler name. 복잡한 변수를 더 간단한 이름으로 캐시합니다. This is useful when accessing an ..
-
-
[파이썬] count, Counter with dictionaryPython/이것저것 파이썬 2022. 8. 30. 07:31
list.count() # list.count() 메서드를 이용. some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n'] duplicates = set() for each in set(some_list): if some_list.count(each) > 1: duplicates.add(each) print(duplicates) # 컴프리헨션으로 정리 duplicates = set(each for each in set(some_list) if some_list.count(each) > 1) print(duplicates) dictionary # 딕셔너리를 이용. some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n'] counte..
-
[파이썬] by value, by referencePython/이것저것 파이썬 2022. 8. 24. 14:55
1. by value, by reference 재귀를 이용해 순열을 만들겠습니다. 문자열을 이용하면 잘 작동합니다. 파이썬에서 문자열은 불변(immutable)입니다. def recursive(result, visited): if len(result) == 3: print(result) return for each in 'abc': if each not in visited: visited.add(each) recursive(result + each, visited) visited.remove(each) # 순열~! recursive('', set()) # abc # acb # bac # bca # cab # cba 출처: https://comdoc.tistory.com/entry/파이썬-순열과-조합 [C..
-
파이썬을 추천합니다.Python/이것저것 파이썬 2022. 8. 22. 17:32
추천의 이유 1. 재미있습니다. 파이썬으로 알고리듬 문제를 풀면서.. 처음 프로그래밍 언어를 배웠을 때의 즐거움을 다시 느낄 수 있었습니다. 2. 넓은 응용 범위 파이썬으로 할 수 있는 것들 웹서버, 웹 크롤링, GUI, DB 응용, 해킹, 사무자동화... 심지어 인공지능도 파이썬으로 많이 하죠. 금융권에서도 파이썬을 많이 씁니다. 퀀트 투자법에도 파이썬을 많이 사용하죠. 상용 게임에도 사용되는데 연산이 필요한 부분에 사용되는 건 아니고, 파이썬은 느립니다. 연산이 필요한 부분은 C++을 많이 사용합니다. 연산 성능이 필요 없거나, 가볍게 자주 변경해야 하는 부분 등에 많이 사용됩니다. 물론 고전 2D 자작 게임 정도는 내장 라이브러리로 끝낼 수 있습니다. 온라인 게임 서버에도 사용할 수 있습니다. '듀..
-
[파이썬] 전략 패턴, 의존성 주입Python/이것저것 파이썬 2022. 8. 16. 10:26
0. '기차는 레일로 이동하고, 버스는 차로로 이동한다.' 는 결과를 만들기 위해 다음과 같이 코드를 작성했습니다. from abc import ABCMeta, abstractmethod class Vehicle(metaclass=ABCMeta): @abstractmethod def move(self): pass class Train(Vehicle): def move(self): print("레일로 이동") class Bus(Vehicle): def move(self): print("차로로 이동") train = Train() bus = Bus() train.move() bus.move() 그런데 버스가 하늘을 나는 시대가 된다면... 다음과 같이 수정을 해야겠죠? class Bus(Transport):..