1

hi i have url like this:

path('api/v1/store/download/<str:ix>/', DownloadVideoAPI.as_view(), name='download'),

it accept long string .

I want to keep allthing after download key in above URL as the parameter.

but when I enter a long string that contains some slash Django says page not found for example when if enter "/api/v1/store/download/asdasd2asdsadas/asdasd" will give me 404 not found ...

how can I do that?

this is my view:

class DownloadVideoAPI(APIView):
    def get(self, request, ix):
        pre = ix.split(",")
        hash = pre[0]
        dec = pre[1]
        de_hash = decode_data(hash, dec)
0

3 Answers 3

1

Well, It's possible to add the extra parameters in the request. you can use re_path method.

# urls.py
from django.urls import re_path

re_path(r'api/v1/store/download/(?P<ix>\w+)/', DownloadVideoAPI.as_view(), name='download'),

ref: https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.re_path

Sign up to request clarification or add additional context in comments.

Comments

0

Just use

path('api/v1/store/download/<str:ix>', DownloadVideoAPI.as_view(), name='download'),

without / at the end.

Comments

0

/api/v1/store/download/asdasd2asdsadas/asdasd will result in a 404 page since Django cannot map the URL, /api/v1/store/download/asdasd2asdsadas/, to a route in your urls.py. To solve this, aside from using BugHunter's answer, you could URL encode your long string first before passing it to your URL.

So, given the long string, "asdasd2asdsadas/asdasd", URL encode it first to "asdasd2asdsadas%2Fasdasd". Once you have encoded it, your URL should now look like "/api/v1/store/download/asdasd2asdsadas%2Fasdasd".


To URL encode in Python 3, you can use urllib.

import urllib

parameter = 'asdasd2asdsadas/asdasd'
encoded_string = urllib.quote(parameter, safe='')

encoded_string here should have the value, "asdasd2asdsadas%2Fasdasd".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.