python - How can I get the path of form, before it produced in view, Django -
i have such problem: have form, displays on every page of web-site. so, action specified(separate) view:
def subscribe(request): if request.method == "post": form = subscriptionform(data=request.post) if form.is_valid(): form.save() return redirect() # there problem else: raise http404
after success handling of form, want redirect user page, form sent. if use request.path
- returns me url handles form. need url of page...
do understand? should do?
thanks lot!
you'll need add additional field form let view know redirect to. simplest way add hidden input form:
<form action="/some/url/" method="post"> ... <input type="hidden" name="next" value="{{ request.path }}"> </form>
the value of request.path
path of page before user submits form.
in view, can use parameter next
redirect user page came from.
def subscribe(request): ... next = request.post.get('next', '/some/default/url/here/') return redirect(next)
Comments
Post a Comment