changebad.blogg.se

Flask app builder action ask prompt
Flask app builder action ask prompt











flask app builder action ask prompt

Let me give you an example of how you use it everyday. The internet uses it to interact and communicate with computers and servers. What is HTTP and What Does it Have to do with Flask? All the code used in the tutorial is available in this GitHub Repository. But you get the idea.In each section, I will show pieces of code for you to follow along. (That's untested, not sure how that would fare. nfirmation_template, **self.get_confirmation_context()) Return super(ConfirmationViewMixin, self).post() Something like: class ConfirmationViewMixin(object): Update: If you really wanted a generic solution that worked with POSTs, I would switch to class-based views and create a mixin that handles the confirmation logic. (See Why shouldn't data be modified on an HTTP GET request?) Note though that doing this redirecting will only work if the view you are wrapping accepts a GET, and it's not a good idea to allow GETs for any operation that modifies data. Return render_template('_confirm.html', desc=desc, action_url=action_url) from functools import wrapsįrom urllib import urlencode, quote, unquoteįrom flask import Flask, request, redirect, url_for, render_templateĭesc=desc, action_url=quote(request.url)))Īction_url = unquote(request.args) Then, you can wrap any view you need confirmation for with it, passing in a function to get the message you want to display. That said, if you're only looking for a server-side solution, you could create a decorator to handle the redirects. It's not visually pretty, but a nfirm('Are you sure?') would do the same thing. I think the simplest approach would be to do the confirmation client-side. I hope that makes sense! Just to note, desc and subject are passed for the confirmation template, and the kwargs is just to catch anything url_for() needs in building the urls.

flask app builder action ask prompt flask app builder action ask prompt

Which then redirects again to do the actual action after validating the confirmation form: do_del_user(user_id): Return render_template('_confirm.html', form=form, desc=desc, subject=subject) Return redirect(url_for(action, confirm=, **kwargs)) If arg != 'action' or arg != 'desc' or arg != 'subject': Which redirects over to the confirm route: methods=) Return redirect(url_for('main._confirm', desc=desc, subject=subject, action=action, next=next, user_id=user.id)) Next = url_for('admin.get_user', user_id=user.id) Is there a more optimal solution to this?Ĭurrently I have a route to initiate the action: del_user(user_id): My current method (detailed below) works, but feels quite clunky and seems like a huge amount of work for a simple task. I'm creating a site using the Flask framework, and am implementing a confirmation page for (mainly administrative) actions i.e.













Flask app builder action ask prompt