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 7832293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:08:40+00:00 2026-06-02T12:08:40+00:00

Is it possible to alter the contents of a view/template based on specific user-defined

  • 0

Is it possible to alter the contents of a view/template based on specific user-defined settings in development.ini or production.ini.

As an example say I am developing a pyramid web-app that lists all the students of the class. The back-end database has only one table – ‘student’. Now I develop an optional script that also adds a table ‘teacher’ to the database. Ideally the web-app should be able to run for both the cases. If teacher table is missing, it will not query it and simply print student details. If teacher table is present, it will print name of the teacher along with the name of the student.

To my mind this can be accomplished in one of the following ways –

  1. Keep separate routes (URLs) for teacher+student and student only
    pages. The problem is that you cannot stop people from actually
    calling the former when you only have student info. This will lead
    to unnecessary error pages
  2. Use a setting teacher_enabled=true/false in .ini file. The setting can be accessed in __ init __.py file through settings[‘teacher_enabled’]. Configure just a single route (say’home’,’/’) but map it to different views based on whether seeting variable is true/false. This will not allow for use of @view_config decorator and templates for both cases will have to be separate
  3. Again using the setting variable, pass it to the view somehow. Make only relevant queries in the view. E.g. – If the teacher_enabled is True, query the teacher table else query the student table only. Pass this variable to templates too and there decide if some details are to be displayed (e.g. teacher name).

So my question is which of these approaches should I use? In case settings variables are to be passed to the views, how can that be done? And is there a standard way of dealing with this problem?

  • 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-02T12:08:43+00:00Added an answer on June 2, 2026 at 12:08 pm

    Keep separate routes (URLs) for teacher+student and student only pages. The problem is that you cannot stop people from actually calling the former when you only have student info.

    Ah, but you can! Combine it with number 2: Add a teacher_enabled=true/false setting to your .ini file, and then you can use some code similar to this:

    from pyramid.threadlocal import get_current_registry
    from pyramid.httpexceptions import HTTPFound
    
    #Define some awesome student views here
    @view_config(name='student')
    def student(request):
        return HTTPFound('Foo!')
    
    if get_current_registry().settings['teacher_enabled']:
    
        #Some awesome student and teacher views here
        @view_config(name='student_and_teacher')
        def student_and_teacher(request):
            return HTTPFound('Bar!')
    

    Number 3 is also feasible. Just remember: It’s easier to ask for forgiveness than permission. So you could do something like this: (Using SQLAlchemy as an example)

    from your_models.teacher import Teacher
    from sqlalchemy.exc import NoSuchTableError
    
    try:
        teacher = session.query(Teacher).filter(Teacher.id==42).first()
    except NoSuchTableError:
        teacher = Teacher('Unknown')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to alter an html attribute of a Zend_Form_Element in a Decorator
Is it possible to alter the text of a UILabel whist its superview is
Is it possible to alter the visible property of hyperlinks on a masterpage at
Is it possible to both alter a column and add a new column in
Is it possible to log CREATE / ALTER statements issued on a MySQL server
I am trying to alter svg image colors with javascript. Is this possible? Can
I'm attempting to alter the contents of certain parts of a HTML form through
Possible Duplicate: Using Ember.js, how do I run some js after a view is
Is there any way to (robustly) reset any possible :after and :before CSS rules
I'm using Visual Studio 2010 RC. Would it be possible that after doing my

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.