combining redirect and render ???

Hi, its me again, i was coping with my problem for a while on my own but right now i have to ask something to the helpful swarm-intelligence in here.
i think i am not the first one with a similar question and i won’t be the last, but googeling it here or in StackOverflow didn’t really gave me a clue.

Description of problem is simple:

let`s say, i surf on the url-page “list-email.html” in my project. if a certain button is clicked, i want to switch to “show.html” with all its funcionlities. but doing

return render(request, 'show.html', context)

only gives me a proper view of the page with still list-email.html in the URL Bar of Browser and also lacks further functionalities of show.html…

Using redirect don’t gives me the content. There must be a simple solution for this???

It all depends on what you mean by “button” here.

The archetypal answer is that the button should really be an a tag - a link to a different page. (You can format that tag to look like a button, but not be one.)

1 Like

Hello again Ken,

so this is exactly what i thougt and tried. But wenn I test following template code on page “list-phone.html”, the button-submit event is properly done but afterwards i am still on “list-phone.html” in Browser and not on “show.html” ???

      <button type="submit" name="id" value="{{ }}"
              class="btn-sm bg-transparent border border-0 rounded-1">
              <a href="{% url 'show' %}"><b>{{ phone.last_name }}</b></a>

and “show” in a is defined in like so:

path('show.html',, name='show'),

Never mind, after you encouraged me to search for solution in template, i put the target URL in the belonging form - action tag. now it works :slight_smile:

<form method="post" target="_self" action="{% url 'show' %}">

Ahh - two things.

First, you never mentioned in your original post that a form was involved. Had I known that, we could have gotten to that solution directly.

Second, the reason the link you defined didn’t work was because it was still inside the button. If you had just rendered the a tag by itself, and not within a button tag, that would have worked to send you to that other page. (It also would not submit the form you’re in, but that being necessary wasn’t known to me at the time.)

Anyway, glad to see you have it working!

1 Like

Thx for your remarks, althouth i have read them much later…it is much worse than that…id had a form in a form-tag in my html file …but i am learning every day :slight_smile: Thx for your continuing advisory. I Appreciate it very much!