Skip to content
Advertisement

How can i pass a dynamic url to another url

Im new to Django. So, my problem is that i want my dynamic url like this:

website.com/password/2332

“2332” is the dynamic part

to pass to this:

website.com/password/2332/revealpassword

urls.py:

path("password/<str:link>", views.password),
path("password/<str:link>/revealpassword", views.reveal_password, name="reveal_password")

html file:

<a href="{% url 'password:reveal_password' link %}">Reveal</a>

the Problem is at the “link”. How can i pass the stuff that is in the url to the new url

Advertisement

Answer

Your view should pass it to the context when you render the template. So your password view looks like:

def password(request, link):
    # …
    context = {
        # …,
        'link': link
    }
    return render(request, 'some_template.html', context)

this thus will “inject” the link when you render the template, such that you can use the link in the {% url … %}.

Advertisement