I am using django rest framework to generate a file, I have this function in my views.py
:
def InformacionBibTex(request, bloque, idUsuario):
print('BLOQUE', bloque)
#...
return response
I use this function to use it in my urls.py
:
urlpatterns = [
path('informacion_bibtex/<slug:bloque>/<int:idUsuario>', views.InformacionBibTex),
]
slug:bloque
In this url I pass a and a as parameters int:idUsuario
to be able to use them in my function.
I pass the parameters from my frontend service in Angular through a request Get
:
generaInformacionBibTex(bloque, id_user){
const httpOptions = {
responseType: 'blob' as 'json',
};
return this.http.get(this.url + 'informacion_bibtex/' + bloque + '/' + id_user, httpOptions);
}
The URL that I send to my server is this:
http://localhost:8000/api/informacion_bibtex/ARTÍCULOS/127
The problem I have is that when making the request to the server it gives me the following error
"GET /api/informacion_bibtex/ART%C3%8DCULOS/127 HTTP/1.1" 404 11500
This due to the tilde that it has ARTÍCULOS
, the server puts various characters such as percentages and numbers.
The same thing happens with spaces:
"GET /api/informacion_bibtex/GRADO%20ACAD%C3%89MICO/127 HTTP/1.1" 404 11520
In this case what I send is:
http://localhost:8000/api/informacion_bibtex/GRADO ACADÉMICO/127
How can I make the server accept the request Get
that I make from my frontend with parameters that contain accents and spaces. I hope you can help me. Thank you!
The URL dispatcher is expecting a slug but is not receiving it. A slug only allows ascii letters, numbers, hyphens and underscores, anything else will not fall under that rule.
You can change the URL definition to receive strings with:
Or, if you want to use slugs and are expecting to access a model by name, use slugify to override the model save.