Skip to content

Instantly share code, notes, and snippets.

@alexkahn
Created September 23, 2015 16:47
Show Gist options
  • Save alexkahn/4075934201a5a86c4224 to your computer and use it in GitHub Desktop.
Save alexkahn/4075934201a5a86c4224 to your computer and use it in GitHub Desktop.
pass a query param to a form
from .forms import AccountCreationForm
class IndexView(TemplateView):
template_name = 'myapp/mytemplate.html'
def get_context_data(self, **kwargs):
ctx = super(IndexView, self).get_context_data(**kwargs)
# you can use any query param key you'd like...
ctx['form'] = AccountCreationForm(initial={'promotion_code': self.request.GET.get('c', '')})
return ctx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment