Python
-
Flask file upload(multipart)Python 2022. 7. 31. 19:53
플라스크로 파일 업로드 서버 만들기 multipart/form-data 2022.08.08 - multipart form-data 와 boundary 2020.07.13 - Flask 서비스 폴더 권장 구조 2022.08.08 - OkHttp 파일 전송(Multipart) UploadHtm파일 templates/upload.htm multipart/form-data 방식 upload1py파일 upload1.py import os import flask #from flask import Flask, request from werkzeug.utils import secure_filename app = flask.Flask(__name__) @app.route("/") def root_page(): retur..
-
Flask render_templatePython 2022. 7. 31. 18:32
render_template()은 templates폴더 안에있는 html을 접속한 웹브라우저에 전달한다. 만들어둔 하나의 html에 데이터를 입력할 수 있어 다양하게 활용가능하다. 기본 예제 ./templates/test1.html @app.route('/test') def test_page(): return render_template('test1.html') Jinja2방식으로 데이터 전달 Jinja2 템플릿 작성하는 방법 요약 {% ... %} - 문장(Sentences) {{ ... }} - 표현식(Expressions) {# ... #} - 주석 # ... ## - 라인문장 html파일에 "{{ title1 }}"라고 넣어두어 준비. 전달 데이터 titlename은 {{ title1 }} 입니다..
-
가변 파라미터Python 2022. 7. 23. 08:14
def varfun1(*args, **kwargs): print("cnt_args = " + str(len(args))) print("cnt_kwargs = " + str(len(kwargs))) >>> def varfun1(*args, **kwargs): ... print("cnt_args = " + str(len(args))) ... print("cnt_kwargs = " + str(len(kwargs))) ... >>> >>> varfun1(11) cnt_args = 1 cnt_kwargs = 0 >>> varfun1(11, b=22) cnt_args = 1 cnt_kwargs = 1 >>> varfun1(11, b=22, [11,22,33]) File "", line 1 varfun1(11, b=..
-
컴프리헨션(Comprehension)Python 2022. 7. 23. 07:57
컴프리헨션 Comprehension 자료구조 생성자에서 단순 생성이 아닌, 문법을 해석하여 자료구조를 만들어 내는 것. Comprehension: 이해력, (언어) 이해력 연습 >>> [a for a in range(3)] [0, 1, 2] >>> [print("cur:"+str(a)) for a in range(3)] cur:0 cur:1 cur:2 [None, None, None] >>> [print("cur:"+str(a)) for a in range(3) for b in range(2)] cur:0 cur:0 cur:1 cur:1 cur:2 cur:2 [None, None, None, None, None, None] >>> [a for a in range(3) for b in range(2)] [..
-
Flask - Android환경에 Java와 연동Python 2021. 10. 25. 15:43
클라이언트 측인 Android환경에서는 Volley를 사용한다. Android - Volley 기본 예제 서버측 flask에서는 import flask app = flask.Flask(__name__) @app.route("/test1") def rt_test1(): return flask.jsonify({'tk':'tokentest1'}), 200 app.run(host='0.0.0.0') Android에서는 volley.Response.Listener을 이용해 응답 왔을 때 처리를 등록 한다. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.acti..
-
Python popenPython 2021. 6. 23. 22:42
외부 파일을 실행하고 출력 확인 System >>> import os >>> r = os.popen("dir *.exe").read() The system cannot find the path specified. >>> r ' Volume in drive C is VdW7u\n Volume Serial Number is 0000-0000\n\n Directory o f C:\\Python38\n\n2020-07-20 16:03 100,424 python.exe\n2020-07-20 16 :03 98,888 pythonw.exe\n 2 File(s) 199,312 bytes \n 0 Dir(s) 8,375,424 bytes free\n' Subprocess >>> import subprocess >>> r..
-