25%
41,250원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
CSS가 적용이 안됩니다..
위 이미지처럼 아무런 기능도 없는 상태에서 그냥 run.py 하고 __init__.py, index.html, style.css만 만든 상태에서 구글 폰트를 적용시키려고 해봤는데 run.py를 구동시키지 않고 index 파일을 웹페이지에서 실행해보면 CSS가 적용이 되는데 run.py를 구동시킨 다음에 localhost로 접속을 해보면 CSS가 적용이 안된 페이지가 뜹니다...왜 그럴까요?
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
docker 이미지로 구동중인 서버 파일 다운로드 관련 문의
자꾸 문의만 이렇게 남겨 죄송합니다 ㅠㅠ docker 이미지로 만든 서버에 테스트를 진행하는중에 파일이 업로드는 되는데 다운로드를 클릭시 404 error가 발생하여 문의드립니다. 강의에서 말씀해주신대로 file attach 경로를 uploads로 변경후에 폴더도 생기고 업로드시 파일도 잘 생깁니다.
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
pymongo.errors.ServerSelectionTimeoutError: mongo:27017: [Errno 113] No route to host
Docker네트워크를 아래처럼 만들고 mongo 이름을 가진 컨테이너를 넣어주고 Web 이미지 생성후 접근했을때pymongo.errors.ServerSelectionTimeoutError: mongo:27017: [Errno 113] No route to host 같은 에러가 나옵니다. 컨테이너 내부에 콘솔로 접근 후에 ping 으로 mongo ip를 붙으면 잘됩니다.. mongodb://mongo:27017을 172.18.0.2 이렇게 ip로 해도 오류가 나옵니다..
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
날짜 검색기능 관련해서 질문드립니다.
기본적인 키워드 검색 이후에 날짜검색기능을 추가시키고 싶은데 프론트 엔드부분에서 이렇게 검색을 받고 키워드와 마찬가지로 url_for 함수를 써서 백엔드 부분에 넘겼습니다. 몽고 DB에서 사용중인 UTCtime으로 변환해서 쿼리부분을 $and 후 pubtime에 대해서 lte,gte 검색을 해야할것같은데 이런식으로 넘어가서 형태변환을 어떻게 줘야할지 잘 모르겠습니다..ㅠㅠ 조언 부탁드립니다
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
게시글 넘버링에 대해서 질문드립니다.
강의 내용에는 게시글 번호가 앞페이지부터 인덱스가 증가합니다. 그런데 보통 사이트 게시판을 보면 맨 뒷페이지부터 인덱스가 증가하는 것이 일반적이라 제가 그렇게 해보고 싶어서 이렇게 저렇게 시도를 해봤는데 도무지 어떻게 하는건지 잘 모르겠습니다. 혹시 본 강의의 코드 {{loop.index + (page - 1) * limit }} 처럼 한 줄로 구현이 가능한 로직인지 아니면 다른 방법으로 만들어야 하는지 알고 싶습니다.
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
에러 다시 한 번 질문드립니다.
이전 질문글에서 jinja2 에러가 주석처리되있지만 {% %} 라는 부분이 있어서 에러가 뜬거일수 있다는 답변에 그 부분 지웠더니 바로 다른 에러가 떴습니다. run.py와 write.html, view.html 모든 부분 다 올립니다. 주석처리되있던 한글로 쓴 설명도 다 지웠습니다. run.py # -*- coding: utf-8 -*- from flask import Flask from flask import request from flask import render_template from flask_pymongo import PyMongo from datetime import datetime from bson.objectid import ObjectId from flask import abort import time app = Flask(__name__) app.config["MONGO_URI"] = "mongodb://localhost:27017/myweb" mongo = PyMongo(app) @app.template_filter("formatdatetime") def format_datetime(value): if value is None: return "" now_timestamp = time.time() offset = datetime.fromtimestamp( now_timestamp) - datetime.utcfromtimestamp(now_timestamp) value = datetime.fromtimestamp((int(value) / 1000) + offset) return value.strftime('%Y-%m-%d %H:%M:%S') @app.route("/view") def board_view(): idx = request.args.get("idx") if idx is not None: board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data is not None: result = { "id": data.get("_id"), "name": data.get("name"), "title": data.get("title"), "contents": data.get("contents"), "pubdate": data.get("pubdate"), "view": data.get("view") } return render_template("view.html", result=result) return abort(400) @app.route("/write", methods=["POST", "GET"]) def board_write(): if request.method == "POST": name = request.form.get("name") title = request.form.get("title") contents = request.form.get("contents") print(name, title, contents) current_utc_time = round(datetime.utcnow().timestamp() * 1000) board = mongo.db.board post = { "name": name, "title": title, "contents": contents, "pubdate": current_utc_time, "view": 0, } x = board.insert_one(post) print(x.inserted_id) return str(x.inserted_id) else: return render_template("write.html") if __name__ == "__main__": app.run(host="0.0.0.0", debug=True, port=9000) write.html <!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>write</title> </head> <body> <table> <form name="form" method="POST" action="/write"> <tr> <td>작성자</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>제목</td> <td><input type="text" name="title" /></td> </tr> <tr> <td>내용</td> <td><textarea name="contents"></textarea></td> </tr> <tr> <td colspan="2"><input type="submit" /></td> </tr> </form> </table> </body> </html> view.html <html> {{result.title}} <br /> {{result.name}} <br /> {{result.pubdate|formatdatetime}} <br /> {{result.view}} <br /> {{result.contents}} </html>
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
docker image 제작관련
명령어를 똑같이 따라했는데 아래와같은 에러가 나옵니다. 받은 이미지를 사용해서 컨테이너내에 들어가서 pip install flask-pymongo 해도 동일하게 에러가 나와요.. dns 문제라고해서 docker dns도 8.8.8.8 로 변경했습니다
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
jinja2.exceptions.TemplateSyntaxError 에러가 뜹니다.
이전까지는 잘되다가 jinja를 쓸 때부터 에러가 뜹니다. 이전 강의 코드는 그대로 따라하니 잘 되었구요, 이번 강의에서 run.py 에 추가된 부분은 @app.template_filter("formatdatetime") def format_datetime(value): if value is None: return "" now_timestamp = time.time() offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp) value = datetime.fromtimestamp((int(value) / 1000) + offset) return value.strftime('%Y-%m-%d %H:%M:%S') @app.route("/view") def board_view(): idx = request.args.get("idx") if idx is not None: board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data is not None: result = { "id": data.get("_id"), "name": data.get("name"), "title": data.get("title"), "contents": data.get("contents"), "pubdate": data.get("pubdate"), "view": data.get("view") } return render_template("view.html", result=result) return abort(400) 이 것들과 기능을 사용하기 위해 import나 선생님 설명 받아적어서 주석처리한 글 몇 줄이 있습니다. 그리고 templates 폴더에 view.html 파일로 <html> {{result.title}} <br /> {{result.name}} <br /> {{result.pubdate|formatdatetime}} <br /> {{result.view}} <br /> {{result.contents}} </html> 이렇게 만들었습니다. 주석으로 설명 몇 자 적어놨구요. 에러 페이지는 jinja2.exceptions.TemplateSyntaxError jinja2.exceptions.TemplateSyntaxError: tag name expected Traceback (most recent call last) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 2463, in __call__ return self.wsgi_app(environ, start_response) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 2449, in wsgi_app response = self.handle_exception(e) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 1866, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/run.py", line 56, in board_view return render_template("view.html", result=result) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/flask/templating.py", line 138, in render_template ctx.app.jinja_env.get_or_select_template(template_name_or_list), File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 930, in get_or_select_template return self.get_template(template_name_or_list, parent, globals) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 883, in get_template return self._load_template(name, self.make_globals(globals)) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 857, in _load_template template = self.loader.load(self, name, globals) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/loaders.py", line 129, in load code = environment.compile(source, name, filename) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 638, in compile self.handle_exception(source=source_hint) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception reraise(*rewrite_traceback_stack(source=source)) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/.venv/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise raise value.with_traceback(tb) File "/Users/magrfs/Desktop/inflearn_nam2/myweb/templates/view.html", line 18, in template 만약에 for문을 쓰거나 if문을 쓰거나할 때는 {% %} 이런식으로 사용하기도 한다. jinja2.exceptions.TemplateSyntaxError: tag name expected The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error. To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side. You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection: dump() shows all variables in the frame dump(obj) dumps all that's known about the object 이렇게 생겼습니다. 눈으로 봐도 모르겠고 디버깅에도 딱히 걸리지 않아서 원인이 뭔지를 모르겠습니다..ㅠㅠ
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
검색어 한글입력
안녕하세요? 열공중인 학생입니다. 검색기능 구현을 열심히 따라하고 있는데 보니 영문 검색은 작동하는데 한글 검색은 동작하지 않고 {'$or': [{'title': {'$regex': 'í\x8c\x8cì\x9d´ì\x8d¬'}}]} 가 프린트 됩니다. 주소창에는 http://localhost:9000/list?search=0&keyword=파이썬 로 잘 나오는 것 같은데 결과는 "데이터가 없습니다." 라고 나옵니다. 해결방법이 궁금합니다.
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
파일 첨부 에러 발생
에러가 발생했는데 검색해봐도 해결방법이 안나오네요... 코딩은 영상과 똑같이 한 것 같습니다만...왜 안될까요..
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
강의 막바지 뷰 수정부분 질문입니다.
board_view 함수 안에서 page, search, keyword 값을 받을 때 def lists 에서는 type을 작성했는데 왜 view 함수에서는 type 값을 안적는건가요? 적든 안적든 상관없는건가요?
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
메소드 오류
F:\PG\Python\Nam\myweb2\run.py:60: DeprecationWarning: count is deprecated. Use Collection.count_documents instead. tot_count = board.find({}).count() 라는 오류가 뜹니다. 검색해보니 find 대신에 count_documents 라는걸 쓰라고 하는거 같은데 제대로 되는건지 모르겠습니다.. tot_count = board.count_documents({}) 라고 쓰면 되는건가요?
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
검색이 제대로 안됩니다.
강의에서는 검색 단어를 '파이썬'으로 하셨는데 똑같이 파이썬으로 검색하면 뭔가 변화는 생깁니다. 그런데 제가 임의로 다른 단어, 예를 들어 제목으로 '왕초보' 라고 검색해보면 검색 결과가 제대로 나오지 않습니다..저만 나오지 않는것인가요? 코드는 에러없이 정상적으로 실행되고 터미널에 {'$or': [{'title': {'$regex': '왕초보'}}]} 라고도 뜹니다.
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
pip install pymongo 오류 문의
visual studio code 터미널에서 pip install pymongo 명령어 실행 시 캡쳐화면과 같이 오류가 나오면서 진행이 안됩니다. 해결방법이 있을까요?
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
데코레이터 함수에 대한 질문입니다..
9:47초쯤에 설명하시는 부분에서 주소를 겟 방식으로 호출했기 때문에 else 부분이 동작하여 render_template가 실행된다고 하셨는데 board_write 라는 함수에 있는 조건문인 request.method가 GET이냐 POST냐를 따지는 것이 제출 버튼을 눌렀을 때만 해당되는 것이 아닌 ~/write 호출했을 때와 제출 버튼을 눌렀을 때 둘 다 적용되는 원리인가요?
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
아이피로는 접속이 되는데 도메인으로는 안됩니다.
http://34.64.201.196/board/list 로 접속하면 접속이 됩니다. rightlife.kr/board/list로 하면 안됩니다. 강의하고 다른 점이라면 네임서버를 등록할 때 강의에서는 옆에 IP 입력란이 자동으로 입력이 됐는데 저는 그게 안떠서 뭘 입력해야 하는지 몰라서 검색해보니 커맨드라인에서 nslookup 명령어를 이용해서 IP를 확인할 수 있다고 하여 확인한 IP 주소를 직접 입력했습니다. 그 외에는 동일합니다.
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
으아...서버 접속이 안되네요...
14:30초 과정까지 따라가서 IP/board/list로 접속해봤지만 접속이 안됩니다... 뭐가 문제일까요...로그 기록 남겨드립니다.. 강의하고 한가지 다른점은..저는 강의 내내 파이썬 3.8을 썼는데 도커 이미지가 3.8이 지원이 안되는거 같아서 3.7로 바꿔서 했습니다...그게 원인인건지... /usr/lib/python2.7/dist-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 'Supervisord is running as root and it is searching ' 2020-03-09 12:59:12,918 CRIT Supervisor running as root (no user in config file) 2020-03-09 12:59:12,918 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing 2020-03-09 12:59:12,935 INFO RPC interface 'supervisor' initialized 2020-03-09 12:59:12,936 CRIT Server 'unix_http_server' running without any HTTP authentication checking 2020-03-09 12:59:12,936 INFO supervisord started with pid 1 2020-03-09 12:59:13,939 INFO spawned: 'nginx' with pid 9 2020-03-09 12:59:13,941 INFO spawned: 'uwsgi' with pid 10 [uWSGI] getting INI configuration from /app/uwsgi.ini [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini ;uWSGI instance configuration [uwsgi] cheaper = 2 processes = 16 ini = /app/uwsgi.ini module = main callable = app i = /etc/uwsgi/uwsgi.ini socket = /tmp/uwsgi.sock own-socket = nginx:nginx chmod-socket = 664 hook-master-start = unix_signal:15 gracefully_kill_them_all need-app = true die-on-term = true show-config = true ;end of configuration *** Starting uWSGI 2.0.18 (64bit) on [Mon Mar 9 12:59:14 2020] *** compiled with version: 6.3.0 20170516 on 14 October 2019 23:20:32 os: Linux-5.0.0-1031-gcp #32-Ubuntu SMP Tue Feb 11 03:55:48 UTC 2020 nodename: 6abf79646e76 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: /app detected binary path: /usr/local/bin/uwsgi your memory page size is 4096 bytes detected max file descriptor number: 1048576 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** Python version: 3.7.4 (default, Sep 12 2019, 16:02:06) [GCC 6.3.0 20170516] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x55e9b9a27f50 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 1239640 bytes (1210 KB) for 16 cores *** Operational MODE: preforking *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55e9b9a27f50 pid: 10 (default app) 2020-03-09 12:59:15,182 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 2020-03-09 12:59:15,182 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 10) spawned uWSGI worker 1 (pid: 15, cores: 1) spawned uWSGI worker 2 (pid: 16, cores: 1) running "unix_signal:15 gracefully_kill_them_all" (master-start)... {} [2020-03-09 12:59:50,638] ERROR in app: Exception on /board/list [GET] Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "./main/board.py", line 45, in lists tot_count = board.find(query).count() File "/usr/local/lib/python3.7/site-packages/pymongo/cursor.py", line 787, in count cmd, self.__collation, session=self.__session) File "/usr/local/lib/python3.7/site-packages/pymongo/collection.py", line 1600, in _count _cmd, self._read_preference_for(session), session) File "/usr/local/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1454, in _retryable_read read_pref, session, address=address) File "/usr/local/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1253, in _select_server server = topology.select_server(server_selector) File "/usr/local/lib/python3.7/site-packages/pymongo/topology.py", line 235, in select_server address)) File "/usr/local/lib/python3.7/site-packages/pymongo/topology.py", line 193, in select_servers selector, server_timeout, address) File "/usr/local/lib/python3.7/site-packages/pymongo/topology.py", line 209, in _select_servers_loop self._error_message(selector)) pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused 175.211.252.65 - - [09/Mar/2020:12:59:50 +0000] "GET /board/list HTTP/1.1" 500 290 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" "-" [pid: 15|app: 0|req: 1/1] 175.211.252.65 () {44 vars in 1942 bytes} [Mon Mar 9 12:59:20 2020] GET /board/list => generated 290 bytes in 30083 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
도메인을 구매하지 않고 깃허브로 가능한가요?
마지막 강의에서 도메인을 구매하셨는데 깃허브를 보니까 계정을 생성해서 저장소 만들고 하면 웹페이지 주소를 주더라고요. 이걸 이용해서 웹페이지 제작을 진행할 수 있나요?
- 해결됨남박사의 파이썬으로 실전 웹사이트 만들기
강의보면서 따라했는데 정상적으로 진행이 안됐어요 ㅠ
강의하고 다른점이라면 모듈을 필요한 것만 일일이 불러와서 노란색 오류도 모두 제거 후 실행을 했습니다.. 근데 글 작성을 누르고 로그인 창이 떴을 때 로그인을 하면 로그인이 안되고 404 오류가 뜨더라고요...그래서 뭐를 수정해야 되는건지 아무것도 모르겠는데 뒷부분에 html 파일에서 액션 부분을 수정하는걸 보고 login.html에서 폼의 액션 속성을 똑같이 바꿔보니까 정상적으로 되더라고요. 근데 남박사님은 그부분은 수정을 안하신거 같은데 왜 정상적으로 되고 저는 왜 안될까요...?
- 미해결남박사의 파이썬으로 실전 웹사이트 만들기
render_template와 redirect의 차이점이 궁금해요?
어떤 경우에 구분해서 사용해야 하는지 궁금합니다