Created
July 6, 2012 12:28
-
-
Save srstanic/3059893 to your computer and use it in GitHub Desktop.
Use it to add Cancel buttons to Django forms, or to open any given URL on button click.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
templatetags module | |
''' | |
from django import template | |
register = template.Library() | |
@register.simple_tag | |
def go_to_url(url): | |
return "window.location='" + url +"'; return false;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/objects/create" method="post">{% csrf_token %} | |
{{ form }} | |
<button onclick="{% go_to_url '/objects' %}">Cancel</button> | |
<button type="submit">Report</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment