Login

Snippets by agore

Snippet List

Allow separation of GET and POST implementations

Django does not have a clean, built-in mechanism to separate GET and POST implementations. This simple decorator provides this behavior. Django does provide an alternate way using class-based views, but defining class for each of your view functions may be an overkill. You can name the get and post functions anything you wish, but you need to make sure they are returned in the same order (get first and then post). Example usage: @formview def edit(request, id): form = EditForm(id, request.POST or None) def get(): return render(request, 'edit.html', {'form' : form}) def post(): if form.is_valid(): form.save(id) return redirect('list') return get, post

  • get
  • decorator
  • post
Read More

agore has posted 1 snippet.