1

I have built an API using Django REST framework and I want to make a PUT request from my AngularJS web-app.

The problem occurs when the id consists of characters like "/".

An example could be the following:

So, as you can expect, the above parsed as 2 parameters and I get 404 (NOT FOUND).

I read this post (slashes in url variables) and then I tried to encode the id to "text%2FadditionalText" (using encodeURIComponent function) but didn't decoded from my server.

I can not change the id because it constructed by some other fields (user input), in order to be human readable.

Community
  • 1
  • 1
Dimitris Makris
  • 461
  • 5
  • 16
  • Is the addtionalText always in the request? If it's the case you can try to code your urlpattern as: urlpatterns = [ url(r'^record/(.*?)/(.*?)/$', views.your_view),] – ainsausti Mar 08 '17 at 08:54
  • It depends on some other fields which are coming from the user input. So sometimes the id could be "texttext" and some others could be "text/text". – Dimitris Makris Mar 08 '17 at 10:24
  • 3
    encodeURIComponent is the right solution in the client, you need to look at your server...depending on the webserver, some automatically translate the url_encoding back (which would be bad in your case), some do give the encoded to the script handler, so you will need to call a url_decode function in your serverside script – cypherabe Mar 08 '17 at 15:33
  • Seems that you're right. I saw in logs of my server that the url is exactly the same with which I'm sending from client. I thought that this process (decode the url) invoked automatically from Django REST framework. – Dimitris Makris Mar 08 '17 at 16:51

0 Answers0