Python flask.render_template() Examples

The following are 30 code examples of flask.render_template(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask , or try the search function .
Example #1
Source File: rl_data.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 14 votes vote down vote up
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') 
Example #2
Source File: web.py    From svviz with MIT License 7 votes vote down vote up
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 
Example #3
Source File: views.py    From everyclass-server with Mozilla Public License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: views.py    From everyclass-server with Mozilla Public License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_index(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)

    return render_template("department/site/index.html", department=department, chart_blocks=department.get_introduction_blocks(), editing=True)

# <<<<<<<< PREVIEW ENDPOINTS >>>>>>>>>> 
Example #6
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_assaults(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/assaults.html", department=department, chart_blocks=department.get_assaults_blocks(), editing=False, published=True) 
Example #7
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def preview_use_of_force(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/useofforce.html", department=department, chart_blocks=department.get_uof_blocks(), editing=False) 
Example #8
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def preview_complaints(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/complaints.html", department=department, chart_blocks=department.get_complaint_blocks(), editing=False) 
Example #9
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_pursuits_schema(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/schema/pursuits.html", department=department, chart_blocks=department.get_pursuits_schema_blocks(), published=True) 
Example #10
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def assaults_schema_edit(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/schema/assaults.html", department=department, chart_blocks=department.get_assaults_schema_blocks(), editing=True)

# <<<<<<<< DATA ENDPOINTS >>>>>>>>>> 
Example #11
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_intro(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/index.html", chart_blocks=department.get_introduction_blocks(), department=department, editing=False, published=True) 
Example #12
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_complaints(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/complaints.html", department=department, chart_blocks=department.get_complaint_blocks(), editing=False, published=True) 
Example #13
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_pursuits(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/pursuits.html", department=department, chart_blocks=department.get_pursuits_blocks(), editing=False, published=True) 
Example #14
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_assaults_schema(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/schema/assaults.html", department=department, chart_blocks=department.get_assaults_schema_blocks(), editing=False, published=True) 
Example #15
Source File: paint.py    From unicorn-hat-hd with MIT License 5 votes vote down vote up
def home():
    return render_template('painthathd.html') 
Example #16
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def assaults_schema_preview(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/schema/assaults.html", department=department, chart_blocks=department.get_assaults_schema_blocks(), editing=False) 
Example #17
Source File: auth.py    From flask-session-tutorial with MIT License 5 votes vote down vote up
def signup():
    """
    Sign-up form to create new user accounts.
    GET: Serve sign-up page.
    POST: Validate form, create account, redirect user to dashboard.
    """
    form = SignupForm()
    if form.validate_on_submit():
        existing_user = User.query.filter_by(email=form.email.data).first()
        if existing_user is None:
            user = User(
                name=form.name.data,
                email=form.email.data,
                website=form.website.data
            )
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()  # Create new user
            login_user(user)  # Log in as newly created user
            print(user)
            return redirect(url_for('main_bp.dashboard'))
        flash('A user already exists with that email address.')
    return render_template(
        'signup.jinja2',
        title='Create an Account.',
        form=form,
        template='signup-page',
        body="Sign up for a user account."
    ) 
Example #18
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_denominators(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template(
        "department/denominators.html",
        department=department,
        denominator_values=department.denominator_values
    ) 
Example #19
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_demographics(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template(
        "department/demographics.html",
        department=department,
        department_values=department.get_raw_department_demographics(),
        city_values=department.get_raw_city_demographics()) 
Example #20
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_assaultsonofficers(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/assaults.html", department=department, chart_blocks=department.get_assaults_blocks(), editing=True) 
Example #21
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_pursuits(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/pursuits.html", department=department, chart_blocks=department.get_pursuits_blocks(), editing=True) 
Example #22
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_use_of_force(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/useofforce.html", department=department, chart_blocks=department.get_uof_blocks(), editing=True) 
Example #23
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edit_ois(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    return render_template("department/site/ois.html", department=department, chart_blocks=department.get_ois_blocks(), editing=True) 
Example #24
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def department_dashboard(department_id):
    department = Department.get_by_id(department_id)
    if not department:
        abort(404)
    current_date = datetime.datetime.now()
    return render_template("department/dashboard.html", department=department, current_month=current_date.month, current_year=current_date.year) 
Example #25
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def admin_dashboard():
    interesteds = Interested.query.all()
    invites = Invite_Code.query.filter_by(used=False)
    users = User.query.filter_by(active=True)
    extractors = Extractor.query.all()
    departments = Department.query.all()
    return render_template("admin/dashboard.html", interesteds=interesteds, invites=invites, users=users, extractors=extractors, departments=departments) 
Example #26
Source File: app.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def register_errorhandlers(app):
    def render_error(error):
        # If a HTTPException, pull the `code` attribute; default to 500
        error_code = getattr(error, 'code', 500)
        return render_template("{0}.html".format(error_code)), error_code
    for errcode in [401, 404, 500]:
        app.errorhandler(errcode)(render_error)
    return None 
Example #27
Source File: routes.py    From flask-session-tutorial with MIT License 5 votes vote down vote up
def session_view():
    """Display session variable value."""
    return render_template(
        'session.jinja2',
        title='Flask-Session Tutorial.',
        template='dashboard-template',
         session_variable=str(session['redis_test'])
    ) 
Example #28
Source File: routes.py    From flask-session-tutorial with MIT License 5 votes vote down vote up
def dashboard():
    """Logged in Dashboard screen."""
    session['redis_test'] = 'This is a session variable.'
    return render_template(
        'dashboard.jinja2',
        title='Flask-Session Tutorial.',
        template='dashboard-template',
        current_user=current_user,
        body="You are now logged in!"
    ) 
Example #29
Source File: auth.py    From flask-session-tutorial with MIT License 5 votes vote down vote up
def login():
    """
    Log-in page for registered users.
    GET: Serve Log-in page.
    POST: Validate form and redirect user to dashboard.
    """
    if current_user.is_authenticated:
        return redirect(url_for('main_bp.dashboard'))  # Bypass if user is logged in

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()  # Validate Login Attempt
        if user and user.check_password(password=form.password.data):
            login_user(user)
            next_page = request.args.get('next')
            return redirect(next_page or url_for('main_bp.dashboard'))
        flash('Invalid username/password combination')
        return redirect(url_for('auth_bp.login'))
    return render_template(
        'login.jinja2',
        form=form,
        title='Log in.',
        template='login-page',
        body="Log in with your User account."
    ) 
Example #30
Source File: views.py    From comport with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def public_uof(short_name):
    department = Department.query.filter_by(short_name=short_name.upper()).first()
    if not department:
        abort(404)
    return render_template("department/site/useofforce.html", department=department, chart_blocks=department.get_uof_blocks(), editing=False, published=True)