Search code examples
djangodjango-urlsdjango-url-reverse

django url _reverse _ not a valid view function or pattern name


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.


Solution

  • 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"));