Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:04:08+00:00 2026-06-15T03:04:08+00:00

I am setting up an application using Flask based on a tutorial I found

  • 0

I am setting up an application using Flask based on a tutorial I found on the web. The problem I am having is so far it seems like I will have to write a lot of code for each view/route that I want to make so I am trying to devise a better system but I think I dug myself into a hole where I wrote too much code before really testing each step and since im not familiar with the framework im kindof lost.

so what I want is a base view class that will extract away some boilerplate stuff. Here is my attempt so far.

import jinja2
from jinja2 import Environment as Jinja2Environment
from webassets import Environment as AssetsEnvironment
from webassets.loaders import YAMLLoader
from webassets.ext.jinja2 import AssetsExtension
from flask import render_template
from app import app

class BaseView(object):

    def __init__(self):
        "init"

    def get_jinja_env(self):
        jinja_env = Jinja2Environment(loader=jinja2.FileSystemLoader('templates/'), extensions=[AssetsExtension])

        return jinja_env

    def get_asset_env(self):
        asset_loader = webassets.YAMLLoader('conf/assets.yml')
        asset_env = asset_loader.load_environment()
        bundles = asset_loader.load_bundles()
        [asset_env.register(name, bundle) for name, bundle in bundles.iteritems()]

        return asset_env

    def render_tmpl(self, tmpl_file, **context):
        "Renders Jinja Template"
        jinja_env = self.get_jinja_env
        jinja_env.assets_environment = self.get_asset_env

        template = jinja_env.get_template(tmpl_file)
        return template.render(context)

Class that attempts to inherit from BaseView

from app.BaseView import BaseView
from app import app

class HelloView(BaseView):

    @app.route('/')
    def respond(self):
        self.render_tmpl('hello.html')

My reasoning behind this is later I intend to extend some Jinja functionality such as caching and have some data be available for every view and template.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:04:10+00:00Added an answer on June 15, 2026 at 3:04 am

    You will want to use the View classes included in flask already.

    As they are very well explained there is not much I could explain here. Just read through the docs and I think you will see, what you will have to do (the flask docs are awesome.)

    If you want to cache you also might want to have a look at Flask-Cache.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting up an application using the MVC model and I have a
I'm having problems settig up my application using Thin and Sinatra. I have created
I am using application builder and setting up select boxes to populate a query
I've been using a pattern in an application where I'm setting arbitrary attributes on
Im using VS2008 and My MFC application has started to crash when setting breakpoints
In my iOS5 iPhone application, i'm setting the tint color of search bar using
I have added some settings to my c# application using the configuration editor. There
I am using external interface to store cookies in client side of application. Like
I have a flask app, I am using celery as a task queue. I
I have been using this guide: http://darts.cse.nd.edu:8080/Plone/materials/setting-up-android-development , to help me build and load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.