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

  • Home
  • SEARCH
  • 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 6017939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:05+00:00 2026-05-23T03:12:05+00:00

Please bear with me, since I am just getting started with Pyramid. I am

  • 0

Please bear with me, since I am just getting started with Pyramid. I am having trouble understanding context and resource in Pyramid, with regards to URL Dispatch. I’m not quite sure what it means from the description in the documentation, context and resource is somewhat circular (to me).

  • What is a resource in pyramid? Is it just what the url is trying to represent?
    For example, if the url is /organization/add_users, is the resource organization or users?
  • Is the context also organization in the example above?

Also,

  • What exactly is a context object?
  • What is the context object supposed to contain? The example in the tutorial only has the ACL and has nothing in the init method.

    class RootFactory(object):
    __acl__ = [(...some permissions...)]
    
    def __init__(self):
        pass
    
  • When an exception is thrown (Forbidden for instance) at what point exactly does the context change?

  • I can see the purpose of the changing context when there is something like a Forbidden error, but when doing something like validation, why should I throw an exception that is registered with a different view_callable, which renders to a different template, when I can simply render to a different template within the same view_callable instead of throwing the exception? (I saw a validation error example for add_view in the docs)

  • 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-05-23T03:12:06+00:00Added an answer on May 23, 2026 at 3:12 am

    First of all, the main reason that you would want to even care about this stuff when using URL Dispatch is for the purposes of using pyramid’s auth system. If you don’t care about that, then you can completely ignore contexts and resource trees and go on with dispatch.

    Resource Trees

    Pyramid has a unique concept of a resource tree, which is literally a tree of objects that is mapped to a path. This tree is traversed from the root down to the end of a supplied path. During traversal if the path is exhausted or the tree hits a leave node, that object in the tree is now the context.

    In URL Dispatch, traversal does not occur (by default), thus the context will always be the root of your resource tree.

    In general, you can use the context for anything you want in your application. It is used explicitly by the ACLAuthorizationPolicy to determine permissions. This is a whole topic, and I’d suggest checking out my demo that explains how to use Pyramid’s auth system with URL Dispatch [1].

    Exceptions

    Exception handling in Pyramid is done in two different ways:

    1. You can use try: except: in your view to return a different response.
    2. You can utilize exception views to more generally handle exceptions within your app.

    Note that the second way is required for rendering 404 pages and if you’re using Pyramid’s auth, forbidden pages too. This is because Pyramid internally throws the NotFound and Forbidden exceptions that you must catch and render if you want to customize them.

    When an exception is thrown and there is an exception view registered to match that type, Pyramid will invoke the exception view and pass in the exception as the new context, so that’s when the context changes.

    I’m not sure validation is a good example of an exception view. More typically the views are used for error cases, or to short-circuit execution in non-view parts of your application. For example you may want to handle and return different pages when your view fails to connect to your database, or when you want to return a 4xx or 5xx response. By default if the exception is not handled, the WSGI server just turns it into a generic 500 page. Exception views let you customize that behavior.

    The important takeaway from all of this is that it’s all optional. If you’re confused, don’t worry because you can utilize Pyramid without these things, and as you grow more comfortable you can begin to incorporate them into your application.

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

Sidebar

Related Questions

I've just started using Qt, so please bear with me. When I use QTableWidget->getItemAt(),
Please bear with me, I'm just learning C++. I'm trying to write my header
I am just learning javascript, so please bear with me! I want to be
Please bear with me on this as I'm still getting the hang on Java.
A longwinded question - please bear with me! I want to programatically create an
I am new to visual studio/asp.net so please bear with me. Using vs 2005
I am a complete beginner trying to develop for FCKeditor so please bear with
This is all hypothetical, so please bear with me. Say I'm writing a tool
This is a long text. Please bear with me. Boiled down, the question is:
I am very new to the entity framework, so please bear with me... How

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.