How can I redirect after POST in Pyramid?

前端 未结 6 1595
花落未央
花落未央 2021-02-04 03:50

I\'m trying to have my form submit to a route which will validate the data then redirect back to the original route.

For example:

  • User loads the page websi
6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 04:08

    A clean way is using the "overload" provided by pyramid for different request types, por example, you can decorate your methods this way:

    @action(request_method='GET',
            renderer='mypackage:/templates/save.mako',
            name='save')
    def save(request):
        ''' Fill the template with default values or leave it blank'''
         return {}
    
    
    @action(request_method='POST',
            renderer='mypackage:/templates/save.mako',
            name='save')
    def save_post(request):
        """ form data is submitted here """"
        # process form
    

    In the HTML, you must call the action form, like

    This way, one method is processed when the method POST is used, and the other when the GET is used. The same name, but two implementations.

提交回复
热议问题