Commit 5463dba4 authored by Priit Laes's avatar Priit Laes

Add basic (and broken?) methodview example.

parent 3fe3d82d
from flask import Flask, redirect, render_template, request
from flask.ext import admin
from flask.views import MethodView
class ViewWithMethodViews(admin.BaseView):
@admin.expose('/')
def index(self):
return self.render('methodtest.html')
@admin.expose_plugview('/_api/1')
class API_v1(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v1")
def post(self, cls):
return cls.render('test.html', request=request, name="API_v1")
@admin.expose_plugview('/_api/2')
class API_v2(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v2")
def post(self, cls):
return cls.render('test.html', request=request, name="API_v2")
# Create flask app
app = Flask(__name__, template_folder='templates')
# Flask views
@app.route('/')
def index():
return redirect('/admin')
if __name__ == '__main__':
# Create admin interface
admin = admin.Admin()
admin.add_view(ViewWithMethodViews())
admin.init_app(app)
# Start app
app.debug = True
app.run()
{% extends 'admin/master.html' %}
{% block body %}
Hello World from MethodTest!<br/>
<form method="POST" action="{{ url_for('.API_v1') }}">
<input type="submit" value="API v1 via POST">
<a href="{{ url_for('.API_v1') }}">v1 via GET</a>
</form>
<form method="POST" action="{{ url_for('.API_v2') }}">
<input type="submit" value="API v2 via POST">
<a href="{{ url_for('.API_v2') }}">v2 via GET</a>
</form>
{% endblock %}
{% extends 'admin/master.html' %}
{% block body %}
This view {{ name }} was accessed using {{ request.method }} request.
<br>
<a href="/">Return</a>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment