當前位置: 首頁>>代碼示例>>Python>>正文


Python flask.render_template方法代碼示例

本文整理匯總了Python中flask.render_template方法的典型用法代碼示例。如果您正苦於以下問題:Python flask.render_template方法的具體用法?Python flask.render_template怎麽用?Python flask.render_template使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask的用法示例。


在下文中一共展示了flask.render_template方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_web

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def make_web(queue):
    app = Flask(__name__)

    @app.route('/')
    def index():
        return render_template('index.html')

    def gen():
        while True:
            frame = queue.get()
            _, frame = cv2.imencode('.JPEG', frame)
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + frame.tostring() + b'\r\n')

    @app.route('/video_feed')
    def video_feed():
        return Response(gen(),
                        mimetype='multipart/x-mixed-replace; boundary=frame')

    try:
        app.run(host='0.0.0.0', port=8889)
    except:
        print('unable to open port') 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:25,代碼來源:rl_data.py

示例2: index

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def index():
    if not "last_format" in session:
        session["last_format"] = "svg"
        session.permanent = True

    try:
        variantDescription = str(dataHub.variant).replace("::", " ").replace("-", "–")
        return render_template('index.html',
            samples=list(dataHub.samples.keys()), 
            annotations=dataHub.annotationSets,
            results_table=dataHub.getCounts(),
            insertSizeDistributions=[sample.name for sample in dataHub if sample.insertSizePlot], 
            dotplots=dataHub.dotplots,
            variantDescription=variantDescription)
    except Exception as e:
        logging.error("ERROR:{}".format(e))
        raise 
開發者ID:svviz,項目名稱:svviz,代碼行數:19,代碼來源:web.py

示例3: show_review

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def show_review(cotc_id: int):
    """查看某個教學班的評價"""
    cotc_id = int(cotc_id)

    review_info = CourseReview.get_review(cotc_id)
    avg_rate = review_info['avg_rate']
    reviews = review_info['reviews']

    cotc = COTeachingClass.get_doc(cotc_id)
    if not cotc:
        return render_template('common/error.html', message=MSG_404)

    if session.get(SESSION_CURRENT_USER, None) \
            and CourseReview.get_my_review(cotc_id=cotc_id, student_id=session[SESSION_CURRENT_USER].identifier):
        reviewed_by_me = True
    else:
        reviewed_by_me = False
    return render_template('course/review.html',
                           cotc=cotc,
                           count=review_info['count'],
                           avg_rate=avg_rate,
                           reviews=reviews,
                           user_is_taking=is_taking(cotc),
                           reviewed_by_me=reviewed_by_me) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:26,代碼來源:views.py

示例4: main

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def main():
    """用戶主頁"""
    try:
        is_student, student = entity_service.get_people_info(session[SESSION_CURRENT_USER].identifier)
        if not is_student:
            return "Teacher is not supported at the moment. Stay tuned!"
    except Exception as e:
        return handle_exception_with_error_page(e)

    pending_grant_reqs = user_service.get_pending_requests(session[SESSION_CURRENT_USER].identifier)
    pending_grant_names = []
    for req in pending_grant_reqs:
        pending_grant_names.append(entity_service.get_people_info(req.user_id)[1].name)

    return render_template('user/main.html',
                           name=session[SESSION_CURRENT_USER].name,
                           student_id_encoded=session[SESSION_CURRENT_USER].identifier_encoded,
                           last_semester=student.semesters[-1] if student.semesters else None,
                           privacy_level=user_service.get_privacy_level(session[SESSION_CURRENT_USER].identifier),
                           pending_grant_names=pending_grant_names) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:22,代碼來源:views.py

示例5: login_required

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def login_required(func):
    """
    a decorator for routes which is only available for logged-in users.
    """

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        if not session.get(SESSION_CURRENT_USER, None):
            return render_template('common/error.html', message=MSG_NOT_LOGGED_IN, action="login")
        return func(*args, **kwargs)

    return wrapped 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:14,代碼來源:web_helpers.py

示例6: home

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def home():
    return render_template('painthathd.html') 
開發者ID:pimoroni,項目名稱:unicorn-hat-hd,代碼行數:4,代碼來源:paint.py

示例7: index

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def index():
    host = request.url_root
    return render_template("index.html", host=host) 
開發者ID:wechatpy,項目名稱:wechatpy,代碼行數:5,代碼來源:app.py

示例8: get_classroom

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def get_classroom(url_rid, url_semester):
    """教室查詢"""
    # decrypt identifier in URL
    try:
        _, room_id = decrypt(url_rid, resource_type='room')
    except ValueError:
        return render_template("common/error.html", message=MSG_INVALID_IDENTIFIER)
    # todo 支持沒有學期的room
    # RPC to get classroom timetable
    try:
        room = entity_service.get_classroom_timetable(url_semester, room_id)
    except Exception as e:
        return handle_exception_with_error_page(e)

    with tracer.trace('process_rpc_result'):
        cards = defaultdict(list)
        for card in room.cards:
            day, time = lesson_string_to_tuple(card.lesson)
            cards[(day, time)].append(card)

    empty_5, empty_6, empty_sat, empty_sun = _empty_column_check(cards)

    available_semesters = semester_calculate(url_semester, room.semesters)

    return render_template('entity/room.html',
                           room=room,
                           cards=cards,
                           empty_sat=empty_sat,
                           empty_sun=empty_sun,
                           empty_6=empty_6,
                           empty_5=empty_5,
                           available_semesters=available_semesters,
                           current_semester=url_semester) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:35,代碼來源:views.py

示例9: get_card

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def get_card(url_cid: str, url_semester: str):
    """課程查詢"""
    # decrypt identifier in URL
    try:
        _, card_id = decrypt(url_cid, resource_type='klass')
    except ValueError:
        return render_template("common/error.html", message=MSG_INVALID_IDENTIFIER)

    # RPC to get card
    try:
        card = entity_service.get_card(url_semester, card_id)
    except Exception as e:
        return handle_exception_with_error_page(e)

    day, time = lesson_string_to_tuple(card.lesson)

    # cotc_id = COTeachingClass.get_id_by_card(card)
    # course_review_doc = CourseReview.get_review(cotc_id)

    return render_template('entity/card.html',
                           card=card,
                           card_day=get_day_chinese(day),
                           card_time=get_time_chinese(time),
                           # cotc_id=cotc_id,
                           # cotc_rating=course_review_doc["avg_rate"],
                           cotc_id=0,
                           cotc_rating=0,
                           current_semester=url_semester
                           ) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:31,代碼來源:views.py

示例10: available_rooms

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def available_rooms():
    return render_template("entity/available_rooms.html") 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:4,代碼來源:views.py

示例11: electives

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def electives():
    return render_template('course/electives.html') 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:4,代碼來源:views.py

示例12: elective_assistant

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def elective_assistant():
    return render_template('course/elective_assistant.html') 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:4,代碼來源:views.py

示例13: disallow_in_maintenance

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def disallow_in_maintenance(func):
    """
    a decorator for routes which should be unavailable in maintenance mode.
    """

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        config = get_config()
        if config.MAINTENANCE:
            return render_template('maintenance.html')
        return func(*args, **kwargs)

    return wrapped 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:15,代碼來源:web_helpers.py

示例14: _error_page

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def _error_page(message: str, sentry_capture: bool = False, log: str = None):
    """return a error page with a message. if sentry is available, tell user that they can report the problem."""
    sentry_param = {}
    if sentry_capture and plugin_available("sentry"):
        sentry.captureException()
        sentry_param.update({"event_id": g.sentry_event_id,
                             "public_dsn": sentry.client.get_public_dsn('https')
                             })
    if log:
        logger.info(log)
    return render_template('common/error.html', message=message, **sentry_param) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:13,代碼來源:web_helpers.py

示例15: check_permission

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import render_template [as 別名]
def check_permission(student: StudentTimetableResult) -> Tuple[bool, Optional[str]]:
    """
    檢查當前登錄的用戶是否有權限訪問此學生

    :param student: 被訪問的學生
    :return: 第一個返回值為布爾類型,True 標識可以訪問,False 表示沒有權限訪問。第二個返回值為沒有權限訪問時需要返回的模板
    """
    can, reason = user_service.has_access(student.student_id,
                                          session.get(SESSION_CURRENT_USER).identifier if session.get(SESSION_CURRENT_USER, None) else None)
    if reason == user_service.REASON_LOGIN_REQUIRED:
        return False, render_template('entity/studentBlocked.html',
                                      name=student.name,
                                      falculty=student.deputy,
                                      class_name=student.klass,
                                      level=1)
    if reason == user_service.REASON_PERMISSION_ADJUST_REQUIRED:
        return False, render_template('entity/studentBlocked.html',
                                      name=student.name,
                                      falculty=student.deputy,
                                      class_name=student.klass,
                                      level=3)
    if not can:
        return False, render_template('entity/studentBlocked.html',
                                      name=student.name,
                                      falculty=student.deputy,
                                      class_name=student.klass,
                                      level=2)

    return True, None 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:31,代碼來源:web_helpers.py


注:本文中的flask.render_template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。