Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic (and broken?) methodview example.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |