python flask 프레임 빠 른 입문
WSGI 공구 상 자 는 Werkzeug(경로 모듈)를 사용 하고 템 플 릿 엔진 은 Jinja 2 를 사용 합 니 다.이 두 가지 도 플 라 스 크 프레임 의 핵심 이다.
Flask 상용 확장 팩:
영문 문서(http://flask.pocoo.org/docs/0.11/)
확장 목록:http://flask.pocoo.org/extensions/
템 플 릿 필터


from flask import Flask,render_template
app =Flask(__name__)
@app.route('/')
def index():
context ={
'name':'engine',
'age':18,
}
return render_template('index.html',**context)
if __name__ == '__main__':
app.run(debug=True)


abs―절대 치



defalut―값 이 없 으 면 기본 값 을 사용 하고 있 으 면 있 는 값 을 사용 합 니 다.




escape(value)또는 e:전의 문자,<,>등 기 호 를 HTML 의 기호 로 바 꿉 니 다.

escape―전의 태그

시작 하면 끝{%autoescape 0ff%},{%endautoescape%}효 과 는|safe 와 같 습 니 다.

첫 번 째 팝 업 창 은 escape 의 필터 입 니 다.

두 번 째 팝 업 창 은 safe 필터 입 니 다.

first、last、length



striptags(value):문자열 에 있 는 모든 HTML 탭 을 삭제 합 니 다.여러 개의 빈 칸 이 있 으 면 빈 칸 으로 바 꿉 니 다.


끼 워 넣 기 사용


replace


truncate(value,length=255,killwords=False):length 길이 의 문자열 을 캡 처 합 니 다.



trim―문자열 앞 과 뒤의 공백 문 자 를 캡 처 합 니 다.



wordcount―긴 문자열 의 단어의 개 수 를 계산 합 니 다.



정의 필터




표준 클래스 보기

이것 은 함수 입 니 다.


이것 은 클래스 보기(/profile/경로)입 니 다.endpoint 는 이름 을 바 꿉 니 다.viewfunc 는 바 인 딩 함수(호출)


동시에 루트 디 렉 터 리 에 url 을 추가 합 니 다.for,이 때 직접 실행 하면 오류 가 발생 합 니 다.


엔 드 포인트 이름 이 바 뀌 었 기 때 문 입 니 다.

해결 방법 은 Urlfor 의 profile 을 endpoint 의 geren 으로 변경 합 니 다.



표준 클래스 보기 사용


오류 가 발생 할 수 있 습 니 다.

views 의 소스 코드 를 보 려 면 views 의 방법 으로 다시 써 야 합 니 다.

클래스 보기 다시 쓰기

성공 하 다

클래스 맵―app.addurl_rule('/경로/',viewfunc=클래스 보기 이름.asview('이름 짓 기')사전 데이터 반환 변환 json 데이터―jsonify()―패키지 가 필요 합 니 다.


등록 페이지



사용자 정 보 를 추가 하 는 동시에 html 에 렌 더 링 합 니 다.



두 사용자 의 이름 이 같 으 면 모두 추출 하여 상속 한다.


스케줄 러 기반 보기


복습 하 다.


이상 은 python flask 프레임 워 크 의 빠 른 입문 에 대한 상세 한 내용 입 니 다.python flask 프레임 워 크 에 관 한 자 료 는 다른 관련 글 을 주목 하 십시오!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.