Reference Django URL in HTML Button
Your specific problem is that you have a conflict with quote types. Use this instead:
onclick="location.href='{% url 'customeroverview' %}'"
but note that this is not really a good way of doing things. If you just want a link that looks like a button, then have a normal a href
and use CSS to style it like a button. In Bootstrap, for example, you can use the "btn btn-*" classes on any element to make it look like a button.
Django - button url
Note:
path(..)
is available from Django-2.0.
The problem here is that friend
is not in the URL:
url(r'^add_friend/$', views.friend_add, name="add_friend"), # no parameter
You can for instance use the primary key (pk
) for the friend by specifying a path(..)
:
path(r'add_friend/<int:friend>/', views.friend_add, name="add_friend"),
In case you work with django-1.x, you can use url(..)
with a regex:
url(r'^add_friend/(?P<friend>[0-9]+)/$', views.friend_add, name="add_friend"),
And now we can use the primary key of the friend in the reverse url:
<input
type="button"
class="btn btn-info"
value="Add Friend"
onclick="location.href='{% url 'user:add_friend' friend=post.poster.pk %}';"
>
(multi-line to make it easier to read).
Attach link to a button in Django
This is HTML problem which you can solve in many ways. One such way is below.
<form>
<button formaction="{% url 'javascript:results' %}">Selenium</button>
</form>
How to use a button to point to an existing url
You can make use of the {% url … %}
template tag [Django-doc]:
<li>
<a href="{% url 'detail' question_id=question.pk">
{{ question.question_text }}</a></li>
<button type='submit'> Result
</button>
</a>
</li>
How can I create redirect button with post method in Django template
from django.conf.urls import include, url
from django.contrib import admin
from rtRegRes.views import spartan , units
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^units/$', units),
url(r'^units/sts/?$', spartan, name='sts'),
]
and
<form method="post" action='sts'>
{% csrf_token %}
<button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="cts_link">cts</button>
</form>
DJango - Redirect to another apps / from a button click
You can use Django URL tag.
<a href="{% url 'myapp:view-name' %}">My link</a>
Example :
<a href="{% url 'portfolio:view-name' %}">Portfolio</a>
Django - How to pass current url parameters if any to a new url after pressing a button
EDIT since the question changed:
It makes more sense to do a POST here probably instead of a GET.
path('export_wallet/', views.export_wallet_view, name='export_wallet'),
.inline {
display: inline;
}
.link-button {
background: none;
border: none;
color: blue;
text-decoration: underline;
cursor: pointer;
font-size: 1em;
font-family: serif;
}
.link-button:focus {
outline: none;
}
.link-button:active {
color:red;
}
<form method="post" action="{% url 'export_wallet' %}" class="inline">
<input type="hidden" name="fecha_inicio" value="{{ fecha_inicio }}">
<input type="hidden" name="fecha_fin" value="{{ fecha_fin }}">
<button type="submit" name="submit_param" value="submit_value" class="link-button">
This is a link that sends a POST request
</button>
</form>
Hx-push-url doesn’t work on back button click
Adding this javascript code you can reload the page when the user click the back button:
var auxBack = performance.getEntriesByType("navigation");
if (auxBack[0].type === "back_forward") {
location.reload(true);
}
Related Topics
Changing Presence Discord Status
Cannot Convert the Series to <Class 'Int''>
How to Make Print() Accept the User Input in Same Line
Truth Value of a Series Is Ambiguous. Use A.Empty, A.Bool(), A.Item(), A.Any() or A.All()
Calculating Manhattan Distance in Python in an 8-Puzzle Game
How to Change Border Color in Tkinter Widget
How to Find the Shortest Word in a List in Python
Hiding Raw_Input() Password Input
How to Split an Integer into an Array of Digits
Tkinter Ttk Treeview How to Set Fixed Width Why It Change With Number of Column
How to Avoid Last Comma in Python Loop
Python: Pickle.Load() Raising Eoferror
How to Convert a List of Dictionaries to Json in Python/Django
Calculate Sklearn.Roc_Auc_Score for Multi-Class
How to Extract the Entire Row and Columns When Condition Met in Numpy Array
Python: How to Keep Repeating a Program Until a Specific Input Is Obtained