도 아마추어가 VisualStudio에서 Flask를 이용했을 때의 TIPS
16390 단어 VisualStudio파이썬Flask
Flask의 초기 구성

시작 파일 (runserver.py)
기본적으로 시작 파일은 runserver.py입니다.
"app.run"함수를 실행하여 앱을 시작시키는 것만이 runserver.py 파일의 역할입니다.

솔루션 탐색기의 '201114FlaskScraping' 폴더 바로 아래에 'init_.py'라는 파일이 있습니다. 이 이름의 파일을 만들면 _201114FlaskScraping을 패키지로 가져올 수 있습니다.
'runserver.py'는 '_201114FlaskScraping이라는 패키지'를 가져와서 그것을 시작시키는 것뿐입니다.
"from _201114FlaskScraping import app"
runserver.py
from os import environ
from _201114FlaskScraping import app
from _201114FlaskScraping import hensu
if __name__ == '__main__':
HOST = environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
#本番ローカル変数を取得して切り分け
if hensu.debug_int()==0:
app.run(HOST, PORT)
else:
#テスト環境ではdebugはTrue
app.run(debug=True, host='0.0.0.0', port=int(environ.get('PORT', 5000)))
init.py의 역할
init.py의 두 가지 주요 역할이 있습니다.
①python 스크립트가 있는 디렉토리를 나타낸다
② 필요한 모듈을 import하는 등의 초기화 처리를 기재하고, 초기화
__init__.py
"""
The flask application package.
"""
from flask import Flask
app = Flask(__name__)
import _201114FlaskScraping.views
라우팅

view.py
"""
Routes and views for the flask application.
"""
from datetime import datetime
from flask import render_template
from _201114FlaskScraping import app
@app.route('/')
@app.route('/home')
def home():
"""Renders the home page."""
return render_template(
'index.html',
title='Home Page',
year=datetime.now().year,
)
@app.route('/contact')
def contact():
"""Renders the contact page."""
return render_template(
'contact.html',
title='Contact',
year=datetime.now().year,
message='Your contact page.'
)
@app.route('/about')
def about():
"""Renders the about page."""
return render_template(
'about.html',
title='About',
year=datetime.now().year,
message='Your application description page.'
)
form/input에서 서버측에 값 전달
"method="POST"action="/about""으로 서버에 던지기
index.html
<form method="POST" action="/about">
<label>テキスト:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
<button type="submit">送信</button>
</form>
@app.route('/about',methods=['POST'])'로 받기
views.py
@app.route('/about',methods=['POST'])
def about():
"""Renders the about page."""
return render_template(
'about.html',
title='About',
year=datetime.now().year,
message='Your application description page.'
)
/about 페이지가 표시됨

Flask의 기능을 추가해 나가는 방향성
기본적인 방침은 views.py에 기능을 늘리는 것입니다.
단지, 프로그램이 번잡해지기 때문에 「BluePrint」를 사용해 간다고 하는 것...(계속한다
py 파일을 읽고 사용
module1.py 만들기

module1.py
def test_func():
return('aaaaa')
views.py
"""
Routes and views for the flask application.
"""
from datetime import datetime
from flask import render_template
from _201114FlaskScraping import app
from _201114FlaskScraping import module1
@app.route('/')
@app.route('/home')
def home():
"""Renders the home page."""
return render_template(
'index.html',
title='Home Page',
year=datetime.now().year,
)
@app.route('/contact')
def contact():
"""Renders the contact page."""
return render_template(
'contact.html',
title='Contact',
year=datetime.now().year,
message='Your contact page.'
)
@app.route('/about',methods=['POST'])
def about():
"""Renders the about page."""
mess=module1.test_func()
return render_template(
'about.html',
title='About',
year=datetime.now().year,
message=mess
)
참고 : htps : // 이 m/k k7679/이고 ms/f12에 2794b1~b0625d9후아
selenium을 사용해보기

웹 드라이버 배치

참고 : htps : // m / nsuhara / ms / 76 굳 132734b7 에 2b352d
참고 : htps : // 이 m / ymgn_ 1 / / ms / 4c2964 a 14 f80 또는 2 28
알림을 위해 라인 사용
Reference
이 문제에 관하여(도 아마추어가 VisualStudio에서 Flask를 이용했을 때의 TIPS), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/healing_code/items/02014719aada2fc7d771텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)