Python

[Django] Ajax로 다차원 배열, Json안에 Json 등 중첩된 구조의 데이터 전송하는 방법 AJAX로 Django 서버로 데이터를 전송 할 때, 다음과 같이 중첩된 구조의 데이터(multidimensional array, json, 등)을(를) 전송하는 경우, View에서 데이터를 갖고 오는 방법이다. # 예시 데이터 { data: "트리", tasks: { name1: [0, 'aaa'], name2: [1, 'bbb'] } } 1. getlist 또는 get 이용하기 위 데이터를 views.py에서 출력해 보면 아래와 같은 구조로 출력된다. def test_ajax_post(request): if request.POST: print request.POST # -..
[Django] npm으로 설치한 패키지 사용하는 방법(node_modules) npm으로 패키지를 설치하는 경우 node_modules폴더와 package.json 파일이 생성된다. 1. STATIC_URL 경로 안에 node_modules 폴더가 존재하는 경우 [구조] - 프로젝트 - 프로젝트 폴더 - settings.py - ... - static - node_modules - package.json - ... - manage.py - ...django templates에서 node_modules에 저장된 javascript/css 파일을 사용하기 위해서는 settings.py에 선언된 STATIC_URL 경로에 node_modules가 포함되어 있어야 한다. 즉, STATIC_URL = '..
[Python] 순열과 조합 하나의 리스트에서 모든 조합을 계산하는 방법 1. 순열 itertools.permutations(iterable[, r]) https://www.hackerrank.com/challenges/itertools-permutations/problem iterable: iterable한 값 r: 몇개 씩 묶을 것인지, (미 입력 -> iterable 전체 길이) >>> from itertools import permutations >>> print list(permutations(['1','2','3'])) [('1', '2', '3'), ('1', '3', '2'), ('2', '1', '3'), ('2', '3', '1'), ('3', '1', '2'), ('3', '2', '..
[Python] faker 라이브러리 faker https://faker.readthedocs.io/en/master/index.html 가짜 더미 데이터를 만들어주는 라이브러리. database나 xml등과 같은 곳에 테스트를 위한 더미 데이터를 만드는데 사용할 수 있다. Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is ..
[Django] static 파일 불러오기 static폴더 : css, image, js 파일을 포함하는 폴더이다. 먼저 settings.py에서 static 폴더 위치를 설정해 준다. Django예제에서와 같이 앱들과 동등한 위치에 static폴더를 만들 경우 아래와 같이 staticfiles_dirs에 경로를 추가해 주면된다. // settings.py STATIC_DIR = os.path.join(BASE_DIR, "static") STATIC_URL = '/static/' STATICFILES_DIRS = [ STATIC_DIR, ] s 만약, static폴더를 다른 곳에 만들고 싶다면 어떻게 해야할까? 예를 들어, myapp 이라는 앱 폴더 내에 존재할 경우, 똑같이 경로를 staticfiles..
[Python] 설치된 패키지 목록 requirements.txt 만들기 가상환경(venv)이나 현재 python에 pip으로 설치된 패키지 목록에 대한 정보를 requirements.txt 로 만들기 위해서는 freeze 명령어를 사용하면 된다. $ pip freeze > requirements.txt requirements.txt의 패키지들을 모두 설치하기 위해서는 아래 명령어를 이용하면 된다. $ pip install -r requirements.txt [참고] https://docs.python.org/ko/3/tutorial/venv.html
S0PH1A
'Python' 태그의 글 목록 (2 Page)