Is it possible to include forward slashes ('/') in AJAX routes that correspond to subpatterns in Pyramid?

While experimenting with ajax routes, I discovered that the ajax route match only works for the first forward slash '/'. Anything after the initial forward slash is disregarded.

For instance,

View.py

@view_config(name="a", renderer="json")
def server_viewtest_a(request):
    return {}

@view_config(name="a/b", renderer="json")
def server_viewtest_ab(request):
    return {}

test.js

$.get('a/b', function (result) {  
 });

In the above ajax call to route 'a/b', it mistakenly matches with 'server_viewtest_a' instead of 'server_view_ab'. Subsequent forward slashes are not considered at all.

Is there a way to include forward slashes in ajax call routes? If so, how can this be achieved?

Edit

To clarify, I managed to make it work by using the following code. However, my intention was to utilize 'name' instead of 'route_name' in my @view_config so that I wouldn't need to define each route with "config.add_route()" in my __init__.py file. Is there a method to accomplish this solely using "name"?

__init__.py

config.add_route('a', 'a')
config.add_route('a/b', 'a/b')

View.py

@view_config(route_name="a", renderer="json")
def server_viewtest_a(request):
    return {}

@view_config(route_name="a/b", renderer="json")
def server_viewtest_ab(request):
    return {}

Answer №1

Your Python code is missing a route definition that matches the pattern a/b. Without this route, the second function may not be evaluated due to route declaration ordering.

It's important to declare your routes in order of most specific to least specific when using URL dispatch for route matching. For guidance on how to do this properly, refer to the Pylons project documentation on route declaration ordering.

If you are utilizing URL dispatch for route matching, consider leveraging the @view_config Decorator and consulting the pyramid.view.view_config API documentation for examples on how to configure views.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Button Click to Display Table Data Using AJAX

I want to show the query results on the same page as the button that triggers the query without any redirection. Here is my current setup: <form action="action.php" method="post"> <input type="submit" class="button" id="mail-button" name=' ...

To effectively delete the <li> element using JavaScript, make sure to eliminate the associated array object as well

I am in the process of designing a compact landing page that will randomly select a city from user input to determine the next trip destination. When the user types in the city name into the input field, everything functions correctly - a new list element ...

Switch to admin view after successful login within the angularjs application

My application uses MVC with Node.js and AngularJS on the frontend. The login page has a different top menu compared to other pages. How can I switch between these headers to display in the view? In the AngularJS login controller, I call a service that ch ...

The functionality of Angular UI TimePicker is not functioning as expected

Currently, I am in the process of developing an angular directive that is designed to manage date and time functions. I have integrated Angular's UI Bootstrap into my project but have encountered a peculiar issue with the TimePicker component. While t ...

Django Not Receiving Data from Ajax Request

I am trying to create a basic ajax method that will run once the document is fully loaded. The code I currently have in my JS file is as follows: $(document).ready(function() { $.ajax({ type:'GET', url: '/get_alert&a ...

"The combination of Google Maps and ASP technology provides innovative solutions

Being a novice in ASP, I recently started working on a small project and could use some guidance. I am looking to create an ASP page that retrieves latitudes and longitudes from a database and uses them to place markers on a map. Below is a snippet of my c ...

SQL Query using Date retrieves Datetime values in a Node application connected to MSSQL

I am currently using version 6.3.1 of node mssql. My query involves multiple columns that are of type date. When querying in node mssql, the output for all Date columns is in this format: 2020-10-20T00:00:00.000Z However, when I execute the same query in A ...

Accessing values from an array within a JSON object using jqGrid

Here is an example of my JSON data: [{"codDiretor":"123", "nomeDiretor":"Nome do Diretor", "data":"29/01/2014", "documentos":[{"codDocumento":"1", "nomeDocumento":"Primeiro Doc"}, {"codDocumento":"2","nomeDocumento":"Segundo Doc"}] ...

Experiencing problems with malfunctioning javascript tabs

As a beginner user and coder, I'm currently working on creating a portfolio website. I had the idea to implement tabs that would allow for content swapping, but unfortunately, I'm having trouble getting the JavaScript to function correctly. I at ...

The IE browser consistently retrieves outdated data from its cache

I always encounter the issue of IE browser loading old data from the browser history. To ensure that I am getting the latest data, I consistently need to clear the browser history. Is there a way to consistently load new data without having to manually cl ...

Exploring the possibility of detecting page scrolling in Javascript by clicking on scroll bars

I have implemented a unique feature on my page that allows users to scroll up and down using custom buttons I created. This functionality is achieved by smoothly transitioning between anchor points on the page using jQuery's animate function. However ...

Utilizing AJAX to automatically fill out a form with information retrieved from a MySQL database

I have been attempting to automate the population of a form with data when a gymnast is selected from a dropdown box. I am aware that AJAX needs to be used for this purpose, and despite my best efforts, my lack of proficiency in Javascript has resulted in ...

The transition effect is not activated when using the MUI Drawer with react-router-dom

My goal was to merge the persistent drawer similar to the example on the MUI website with react-router-dom. However, I encountered a problem where the transition effect no longer seems to work properly. The paragraph does not resize to accommodate the open ...

The JQuery countdown timer seems to be stuck and isn't decreasing as expected

I've been working on a jQuery countdown timer that should start at 30:00 minutes and count down to 00:00. However, I'm facing an issue where it gets stuck at 29:59. Here's the code snippet I'm using: var now = new Date(); var newDateOb ...

Struggling to accurately determine the intersection face vertex positions in Three.js

Hello there! I've been immersed in the world of three.js, dealing with loading models using THREE.JSONLoader. Currently, I'm faced with the task of selecting these objects and their faces, which I've managed to do successfully. Now, my goal ...

Error: Webpack module is not a callable function

I have been developing a backend system to calculate work shifts. I am currently facing an issue with posting user input using a module located in services/shifts. While the getAll method is functioning properly, I encounter an error when trying to post da ...

"Instead of opening the page in a popup window, use window.open to open it in a new tab

I am attempting to open a new popup window using this JavaScript code: window.open(myUrl, ""); However, some users are experiencing the page opening in a new tab instead of a popup window. Does anyone know why this may be happening? ...

The loading of DAE models is not supported in Three.js

I'm encountering a major issue with loading a model into Three.js. To start off, I downloaded https://github.com/mrdoob/three.js/ and extracted it onto my local WebMatrix server. Most of the examples run smoothly, except for the ones that are crucial ...

An error occurred while attempting to reset your password on Parse.com (JS SDK) due to an

I am having trouble resetting my password in my angularjs App. I am utilizing Parse (js SDK) as the backend. Even though I am following the documentation and using Parse.User.requestPasswordReset, I keep encountering error 125 which states invalid email ad ...

Utilize JavaScript to dynamically modify the position of an HTML element

I am working on a script that can manipulate the size of a period symbol, making it increase and decrease in size while staying in one place. However, I have encountered an issue where the element moves up or down the page when its size changes. I tried ...