ViewNotFound while Ajax and Pyramids

老子叫甜甜 提交于 2019-12-13 20:12:40

问题


I'm using Pyramid and got a strange issue. I do an ajax request AR in view A. If the request is done, the user is redirected to view B. If the user goes back to A, the ajax request AR will fail, because pyramid does not find any view for the request.

If someone needs code, I'll post it ;-)

Thx & Greetings Tobias

Edit:

Snippet of my init.py

# adding all routes
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('main_page',               '/')
config.add_route('main_contact',            '/contact')
config.add_route('main_discussion_start',   '/discussion/start')
config.add_route('main_discussion_issue',   '/discussion/start/issue={issue}')
config.add_route('main_discussion',         '/discussion/{parameters}/{service}/go')
config.add_route('main_settings',           '/settings')
config.add_route('main_news',               '/news')
config.add_route('main_imprint',            '/imprint')
config.add_route('404',                     '/404')

# ajax for navigation logic, administraion, settigs and editing/viewing log
config.add_route('ajax_get_start_statements',                '/discussion/{url:.*}ajax_get_start_statements')
config.add_route('ajax_get_premisses_for_statement',         '/discussion/{url:.*}ajax_get_premisses_for_statement')
config.add_route('ajax_reply_for_premissegroup',             '/discussion/{url:.*}ajax_reply_for_premissegroup')

config.add_route('ajax_user_login',                          '{url:.*}ajax_user_login')
config.add_route('ajax_user_logout',                         '{url:.*}ajax_user_logout')

config.add_route('ajax_set_new_start_statement',             '/discussion/{url:.*}ajax_set_new_start_statement{params:.*}')
config.add_route('ajax_set_new_start_premisse',              '/discussion/{url:.*}ajax_set_new_start_premisse{params:.*}')
config.add_route('ajax_set_new_premisses_for_X',             '/discussion/{url:.*}ajax_set_new_premisses_for_X{params:.*}')
config.add_route('ajax_set_correcture_of_statement',         '/discussion/{url:.*}ajax_set_correcture_of_statement{params:.*}')

config.add_route('ajax_user_registration',                   '{url:.*}ajax_user_registration')
config.add_route('ajax_user_password_request',               '{url:.*}ajax_user_password_request')
config.add_route('ajax_fuzzy_search',                        '{url:.*}ajax_fuzzy_search')
config.add_route('ajax_get_issue_list',                      '{url:.*}ajax_get_issue_list')
config.add_route('ajax_switch_language',                     '{url:.*}ajax_switch_language{params:.*}')

Head out of view not found in view.py

# 404 page
@notfound_view_config(renderer='templates/404.pt')
def notfound(self):
    """
    View configuration for the 404 page.
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    logger('- - - - - - - - - - - -', '- - - - - - - - - - - -', '- - - - - - - - - - - -')
    logger('notfound', 'def', 'main in ' + str(self.request.method) + '-request')
....

And one example ajax-call

/**
 * TODO: some text
 * @param statement for sending
 * @param issue for sending
 */
this.sendNewStartStatement = function (statement, issue) {
    var csrfToken = $('#' + hiddenCSRFTokenId).val();
    $.ajax({
        url: 'ajax_set_new_start_statement',
        method: 'POST',
        data: {
            statement: statement, issue: issue
        },
        dataType: 'json',
        async: true,
        headers: {
            'X-CSRF-Token': csrfToken
        }
    }).done(function ajaxSendStartStatementDone(data) {
        new InteractionHandler().callbackIfDoneForSendNewStartStatement(data);
    }).fail(function ajaxSendStartStatementFail() {
        alert('fail in ajax 4');
        // canceled while debuging
    });
};

来源:https://stackoverflow.com/questions/33617880/viewnotfound-while-ajax-and-pyramids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!