Guest User

Untitled

a guest
May 30th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. ## forms.py ##
  2. class IndexForm(forms.Form):
  3.     def __init__(self, *args, **kwargs):
  4.         short = kwargs.pop('short')
  5.         super(IndexForm, self).__init__(*args, **kwargs)
  6.  
  7.     origin = forms.CharField(label='Url', required=True)
  8.     type = forms.ChoiceField(choices=(('Simple', 'simple'), ('Extra', 'extra')),
  9.                              label='Type for your shortcut')
  10.  
  11. ## views.py ##
  12. class IndexView(FormView):
  13.     template_name = 'cutter/index.html'
  14.  
  15.     form_class = IndexForm
  16.     success_url = '/'
  17.  
  18.     def form_valid(self, form):
  19.         short = self.create_link(form.cleaned_data)
  20.         redirect('cutter:index', args=(short,))
  21.  
  22. ## index.html ##
  23. ...
  24. <div>{{ short }}</div>
Add Comment
Please, Sign In to add comment