Navigation Menu

Skip to content

Commit

Permalink
Add basic (and broken?) methodview example.
Browse files Browse the repository at this point in the history
  • Loading branch information
plaes committed Dec 22, 2012
1 parent 3fe3d82 commit 5463dba
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/methodview/methodview.py
@@ -0,0 +1,44 @@
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()
12 changes: 12 additions & 0 deletions examples/methodview/templates/methodtest.html
@@ -0,0 +1,12 @@
{% 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 %}
7 changes: 7 additions & 0 deletions examples/methodview/templates/test.html
@@ -0,0 +1,7 @@
{% extends 'admin/master.html' %}
{% block body %}
This view {{ name }} was accessed using {{ request.method }} request.

<br>
<a href="/">Return</a>
{% endblock %}

0 comments on commit 5463dba

Please sign in to comment.