Skip to content

Instantly share code, notes, and snippets.

@srstanic
Created July 6, 2012 12:28
Show Gist options
  • Save srstanic/3059893 to your computer and use it in GitHub Desktop.
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.
'''
templatetags module
'''
from django import template
register = template.Library()
@register.simple_tag
def go_to_url(url):
return "window.location='" + url +"'; return false;"
<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