0

enter image description here

the redirect url is "liveinterviewList/2"

and, ofcourse, I declare that url in url.py more over, when I type that url in browser manualy, it works well. what's the matter?

more question. at this case, I write the user_id on the url. I think, it is not good way to make url pattern. but I don't know how I deliver the user_id variable without url pattern.

please give me a hint.

  • Please copy and paste code instead of using screenshots. It makes it easier to answer your question and search for it. – Alasdair Nov 18 '19 at 15:21

3 Answers3

1

What HariHaraSudhan left out was how to use parameters. For your case, you would want something like:

path(r'liveinterviewList/<int:userId>', ..., name='live-interview'),

And then when you are ready to reverse, use this:

reverse('app:live-interview', kwargs={ 'userId': userId })

where app is the name of the app in which your view lives. If your url lives in the main urls file , you don't need the app: prefix.

2ps
  • 15,099
  • 2
  • 27
  • 47
  • Note that you don't need to use `reverse` with `redirect`. Instead of `return redirect(reverse('app:live-interview', kwargs={ 'userId': userId }))` you can use `return redirect('app:live-interview', userId=userId)` – Alasdair Nov 18 '19 at 15:20
  • I fixed my bug with another opinion, easier way to implement. but your advise is deeper than another answers. so I'll study with your answers. thankyou very much – Jin-hyeong Ma Nov 18 '19 at 15:43
0

Django reverse function accepts the name of the path not the URL.

lets say i have url patterns like this

urlpatterns = [
   path('/users/list', name="users-list")
]

In my view i can use like this

def my_view(request):
     return redirect(reverse("users-list"));
Hari
  • 1,545
  • 1
  • 22
  • 45
  • tough I fix my bug with another answer, your answer is containing more hints. I'll refer to your method next time. thankyou very much – Jin-hyeong Ma Nov 18 '19 at 15:42
0

You should add a name to your path url and use it to redirect.

As the django doc says :

urls :

urlpatterns = [
   path('/name', name="some-view-name")
]

def my_view(request):
    ...
    return redirect('some-view-name')
Epikstar
  • 69
  • 5