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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:52:32+00:00 2026-05-27T07:52:32+00:00

I am looking for a way to redirect users to different routes/templates that is

  • 0

I am looking for a way to redirect users to different routes/templates that is compatible with using @view_config.

I have a function that reads in an uploaded file and attempts to create a new model based on the file content. I was wondering if there was a clean way that I can redirect the user to one of two urls, based on whether the creation of the new model succeeds or there is an error.

If the model creation is successful, I want to redirect the user to the model page. If there is an error, I want to redirect the user to an error page. However, am having trouble breaking out the original function (load_model)’s view_config when rendering the error page.

@view_config(renderer="error.mak")
@view_config(renderer="model.mak",
        route_name='load_model_route')
def load_model(self):
   ...
   model = Model.find_model(model_name)
   if model:
      #redirect to model_route
   else:
      #redirect to model_error_route

Each route would have a @view_config that binds it to a function.

  • 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-27T07:52:32+00:00Added an answer on May 27, 2026 at 7:52 am

    What you are asking is not “How to redirect” but “How to change renderer in the view function”. To answer quickly, I think you could use:

    request.override_renderer = 'other-renderer.mak'
    

    But I don’t think it’s a good idea. Here’s the usual pattern that is used most of the time to handle form submission:

    from pyramid.httpexceptions import HTTPFound, HTTPNotFound
    from pyramid.url import route_url
    from your_app import Model, some_stuff, save_to_db
    
    @view_config(route_name='new_model',
            renderer='model/new.mak', request_method='GET')
    def new(request):
        """Shows the empty form."""
        return {'model': Model(), 'errors': {}}
    
    @view_config(route_name='create_model',
            renderer='model/new.mak', request_method='POST')
    def create(request):
        """Receives submitted form."""
        model = some_stuff()
        if len(model.errors) = 0: # is valid
            # do your stuff, then redirect
            save_to_db(model)
            return HTTPFound(route_url('show_model', request, model_id=model.id))
        # is invalid
        return {'model': model, 'errors': model.errors}
    
    @view_config(route_name='show_model',
        renderer='model/show.mak', request_method='GET')
    def show(request):
        """Shows details of one model."""
        model = Model.find(request.matchdict['model_id'])
        if model is None:
            return HTTPNotFound()
        return {'model': model}
    

    In short:

    • You show an empty form when you have a GET on the route for a new model.
    • You handle the form submission (POST) in a different view function
      • If the data is valid, you do your stuff, then you redirect with HTTPFound
      • If the data is invalid, you return a dict to show the form again, with errors this time
    • You use the same renderer in the GET and POST, but the one in the POST is only used in case of invalid data (otherwise, you redirect).
    • You have another view function to show the created model.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way to redirect a domain to its subdomain via
I am using codeigniter and looking a way to enable directly editting of doc
My problem is that I was looking for way to use both storyboard and
I looking for way to redirect any 404 error into index.php ErrorDocument 404 /index.php
I am looking for a way to redirect all my old domains to a
I was wondering if there was a way using JavaScript to redirect a user
I have been looking for a way to set up what I thought would
I have a fairly simple Rails application that allows users to manage their clients
In my users photo album page they see photos they have uploaded and each
I have a website which allows users to submit photos of wildlife. Once uploaded,

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.