Commit 20d9627a authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #655 from petrus-jvrensburg/examples

Standardise Examples
parents ff84f9b3 7cc72df5
...@@ -22,3 +22,4 @@ examples/forms/files ...@@ -22,3 +22,4 @@ examples/forms/files
.DS_Store .DS_Store
.idea/ .idea/
*.sqlite *.sqlite
env
...@@ -5,8 +5,6 @@ Flask-Admin is a batteries-included, simple-to-use `Flask <http://flask.pocoo.or ...@@ -5,8 +5,6 @@ Flask-Admin is a batteries-included, simple-to-use `Flask <http://flask.pocoo.or
add admin interfaces to Flask applications. It is inspired by the *django-admin* package, but implemented in such add admin interfaces to Flask applications. It is inspired by the *django-admin* package, but implemented in such
a way that the developer has total control of the look, feel and functionality of the resulting application. a way that the developer has total control of the look, feel and functionality of the resulting application.
You can see some examples of how Flask-Admin can be used at `http://examples.flask-admin.org <http://examples.flask-admin.org/>`_.
Browse through the documentation below to learn more about what you can do with Flask-Admin. Or head over to Browse through the documentation below to learn more about what you can do with Flask-Admin. Or head over to
`our GitHub repository <http://github.com/mrjoes/flask-admin>`_ to find out how you can contribute to the project. `our GitHub repository <http://github.com/mrjoes/flask-admin>`_ to find out how you can contribute to the project.
......
...@@ -302,11 +302,38 @@ Check :mod:`flask.ext.admin.contrib.fileadmin` documentation on how to do it. ...@@ -302,11 +302,38 @@ Check :mod:`flask.ext.admin.contrib.fileadmin` documentation on how to do it.
Examples Examples
-------- --------
Flask-Admin comes with few examples: Flask-Admin comes with several examples, that will really help you get a grip on what's possible.
Browse through them in the GitHub repo, and then run them locally to get yourself up to speed in no time:
- `Simple views <https://github.com/MrJoes/Flask-Admin/tree/master/examples/simple>`_
Here we show how to add some simple custom views to your admin interface. They don't have to
be associated to any of your database models. You can fill them with whatever content you want.
- `Custom layout <https://github.com/MrJoes/Flask-Admin/tree/master/examples/layout>`_
Override some of the built-in templates to get complete control over the look and feel of your Admin interface. Either
while using the default Bootstrap 2, or the newer `Bootstrap 3 <https://github.com/MrJoes/Flask-Admin/tree/master/examples/layout-bootstrap3>`_.
- `Simple administrative interface <https://github.com/MrJoes/Flask-Admin/tree/master/examples/simple>`_ with custom administrative views
- `SQLAlchemy model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/sqla>`_ - `SQLAlchemy model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/sqla>`_
Model-based views provide heaps of builtin goodness, making it really easy to get a set of the default CRUD views in place.
This example shows some of the basics.
- `SQLAlchemy model views with custom forms and file handling <https://github.com/MrJoes/Flask-Admin/tree/master/examples/forms>`_
Here, we show some of the more interesting things you can do with very little effort, including customizing the
builtin forms, and adding support for handling file/image uploads.
- `Flask-Login integration example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/auth>`_ - `Flask-Login integration example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/auth>`_
- `File management interface <https://github.com/MrJoes/Flask-Admin/tree/master/examples/file>`_ Use Flask-Login for authentication to hide some of your admin views behind a login wall.
- `Peewee model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/peewee>`_ - `Peewee model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/peewee>`_
Not so keen on SQLAlchemy? Perhaps you'd rather use Peewee?
- `MongoEngine model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/mongoengine>`_ - `MongoEngine model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/mongoengine>`_
... or check this example if MongoDB is more your style.
- `I18n and L10n with Flask-BabelEx <https://github.com/MrJoes/Flask-Admin/tree/master/examples/babel>`_
Do you need to make your Admin interface available in other languages? Luckily, Flask-Admin is built for just that kind of thing.
- `Redis terminal <https://github.com/MrJoes/Flask-Admin/tree/master/examples/rediscli>`_
If you use Redis for caching, then check this example to see how easy it is to add a Redis terminal to your Admin
interface, so you can reach your Redis instance straight from a browser.
This example shows how to integrate Flask-Login authentication with the Flask-Admin using MongoEngine backend. This example shows how to integrate Flask-Login authentication with Flask-Admin using the MongoEngine backend.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/auth-mongoengine/requirements.txt'
4. Run the application::
python examples/auth-mongoengine/app.py
...@@ -137,7 +137,7 @@ if __name__ == '__main__': ...@@ -137,7 +137,7 @@ if __name__ == '__main__':
init_login() init_login()
# Create admin # Create admin
admin = admin.Admin(app, 'Auth', index_view=MyAdminIndexView()) admin = admin.Admin(app, 'Example: Auth-Mongo', index_view=MyAdminIndexView())
# Add view # Add view
admin.add_view(MyModelView(User)) admin.add_view(MyModelView(User))
......
Flask
Flask-Admin
flask-mongoengine
Flask-Login
This example shows how to integrate Flask-Login authentication with the Flask-Admin using SQLAlchemy backend. This example shows how to integrate Flask-Login authentication with Flask-Admin using the SQLAlchemy backend.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/auth/requirements.txt'
4. Run the application::
python examples/auth/app.py
The first time you run this example, a sample sqlite database gets populated automatically. To suppress this behaviour,
comment the following lines in app.py:::
if not os.path.exists(database_path):
build_sample_db()
...@@ -158,7 +158,7 @@ def index(): ...@@ -158,7 +158,7 @@ def index():
init_login() init_login()
# Create admin # Create admin
admin = admin.Admin(app, 'Auth', index_view=MyAdminIndexView(), base_template='my_master.html') admin = admin.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html')
# Add view # Add view
admin.add_view(MyModelView(User, db.session)) admin.add_view(MyModelView(User, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-Login
This example show how to translate Flask-Admin into different language using customized version of the `Flask-Babel <https://github.com/mrjoes/flask-babelex>` This example show how to translate Flask-Admin into different language using customized version of the `Flask-Babel <https://github.com/mrjoes/flask-babelex>`
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/babel/requirements.txt'
4. Run the application::
python examples/babel/app.py
...@@ -13,7 +13,7 @@ app = Flask(__name__) ...@@ -13,7 +13,7 @@ app = Flask(__name__)
app.config['SECRET_KEY'] = '12345678' app.config['SECRET_KEY'] = '12345678'
# Create in-memory database # Create in-memory database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sample_db.sqlite'
app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app) db = SQLAlchemy(app)
...@@ -58,11 +58,23 @@ class Post(db.Model): ...@@ -58,11 +58,23 @@ class Post(db.Model):
# Flask views # Flask views
@app.route('/') @app.route('/')
def index(): def index():
return '<a href="/admin/">Click me to get to Admin!</a>' tmp = u"""
<p><a href="/admin/?lang=en">Click me to get to Admin! (English)</a></p>
<p><a href="/admin/?lang=cs">Click me to get to Admin! (Czech)</a></p>
<p><a href="/admin/?lang=de">Click me to get to Admin! (German)</a></p>
<p><a href="/admin/?lang=es">Click me to get to Admin! (Spanish)</a></p>
<p><a href="/admin/?lang=fa">Click me to get to Admin! (Farsi)</a></p>
<p><a href="/admin/?lang=fr">Click me to get to Admin! (French)</a></p>
<p><a href="/admin/?lang=pt">Click me to get to Admin! (Portuguese)</a></p>
<p><a href="/admin/?lang=ru">Click me to get to Admin! (Russian)</a></p>
<p><a href="/admin/?lang=zh_CN">Click me to get to Admin! (Chinese - Simplified)</a></p>
<p><a href="/admin/?lang=zh_TW">Click me to get to Admin! (Chinese - Traditional)</a></p>
"""
return tmp
if __name__ == '__main__': if __name__ == '__main__':
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, 'Example: Babel')
#admin.locale_selector(get_locale) #admin.locale_selector(get_locale)
......
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-BabelEx
Simple file management interface example. Simple file management interface example.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/file/requirements.txt'
4. Run the application::
python examples/file/app.py
...@@ -29,7 +29,7 @@ if __name__ == '__main__': ...@@ -29,7 +29,7 @@ if __name__ == '__main__':
pass pass
# Create admin interface # Create admin interface
admin = admin.Admin(app) admin = admin.Admin(app, 'Example: Files')
admin.add_view(fileadmin.FileAdmin(path, '/files/', name='Files')) admin.add_view(fileadmin.FileAdmin(path, '/files/', name='Files'))
# Start app # Start app
......
Examples of some Flask-Admin custom WTForms fields and widgets. This example shows how you can define your own custom forms by using form rendering rules. It also demonstrates general file handling as well as the handling of image files specifically.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/forms/requirements.txt'
4. Run the application::
python examples/forms/app.py
The first time you run this example, a sample sqlite database gets populated automatically. To suppress this behaviour,
comment the following lines in app.py:::
if not os.path.exists(database_path):
build_sample_db()
...@@ -156,7 +156,7 @@ def index(): ...@@ -156,7 +156,7 @@ def index():
return '<a href="/admin/">Click me to get to Admin!</a>' return '<a href="/admin/">Click me to get to Admin!</a>'
# Create admin # Create admin
admin = Admin(app, 'Simple Models') admin = Admin(app, 'Example: Forms')
# Add views # Add views
admin.add_view(FileView(File, db.session)) admin.add_view(FileView(File, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
from flask import Flask
from flask import render_template
app = Flask(__name__)
app.debug = True
app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 # 5Mb
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<title>Flask-Admin examples</title>
<meta name="description" content="Live examples of the Flask-Admin package in action. See how you can add your own custom views, change the look & feel of the admin interface, or just add basic CRUD-views for managing your models.">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<style>
.item{
padding-top: 5px;
}
.item hr{
margin-bottom: 0;
}
.item .btn{
margin-bottom: 10px;
}
.item p.lead{
margin-bottom: 5px;
}
.footer p{
margin-top: 25px;
margin-bottom: 45px;
}
</style>
</head>
<body>
<div class="jumbotron">
<h1>Flask-Admin examples</h1>
<p>
These are some of the examples that can be found in the Flask-Admin GitHub repo at
<a href="https://github.com/mrjoes/flask-admin" target="_blank">https://github.com/mrjoes/flask-admin</a>.
Feel free to play around. This site gets refreshed every 10 minutes or so.
</p>
</div>
<div class="container">
<div class="item">
<h2>Simple views</h2>
<p class="lead">Add a few of your own views to the admin interface. You can add links to them in the top navbar,
but you don't have to.</p>
<a class="btn btn-primary" role="button" href="simple/admin/"><i class="fa fa-chevron-right"></i> view example</a>
<hr>
</div>
<div class="item">
<h2>SQLAlchemy models</h2>
<p class="lead">Add some basic CRUD-views for your models.</p>
<a class="btn btn-primary" role="button" href="sqla/simple/admin/"><i class="fa fa-chevron-right"></i> view example</a>
<!--<p class="lead">Define models with multiple primary keys.</p>-->
<!--<a class="btn btn-primary" role="button" href="sqla/multiple_pk/admin/"><i class="fa fa-chevron-right"></i> view example</a>-->
<hr>
</div>
<div class="item">
<h2>Customize the layout</h2>
<p class="lead">Take control of the look & feel of your admin interface.</p>
<a class="btn btn-primary" role="button" href="layout/admin/"><i class="fa fa-chevron-right"></i> view example</a>
<hr>
</div>
<div class="item">
<h2>Files, images & custom forms</h2>
<p class="lead">Define custom forms using form rules, and quickly add file/image management to your application.</p>
<p>Note: a 5Mb limit has been placed on the size of uploaded files & images for this example.</p>
<a class="btn btn-primary" role="button" href="forms/admin/"><i class="fa fa-chevron-right"></i> view example</a>
<hr>
</div>
<div class="item">
<h2>Authentication</h2>
<p class="lead">Use Flask-Login to authenticate users.</p>
<a class="btn btn-primary" role="button" href="auth/admin/"><i class="fa fa-chevron-right"></i> view example</a>
<hr>
</div>
</div>
<div class="container footer">
<p>
</p>
</div>
<!-- Google Analytics tracking -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45533714-1', 'flask-admin.org');
ga('send', 'pageview');
</script>
</body>
</html>
\ No newline at end of file
This example shows how to customize Flask-Admin layout and overall look and feel. This example shows how you can customize the look & feel of the admin interface. This is done by overriding some of the built-in templates.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/layout-bootstrap3/requirements.txt'
4. Run the application::
python examples/layout-bootstrap3/app.py
The first time you run this example, a sample sqlite database gets populated automatically. To suppress this behaviour,
comment the following lines in app.py:::
if not os.path.exists(database_path):
build_sample_db()
...@@ -58,7 +58,7 @@ def index(): ...@@ -58,7 +58,7 @@ def index():
# Create admin with custom base template # Create admin with custom base template
admin = admin.Admin(app, base_template='layout.html', template_mode='bootstrap3') admin = admin.Admin(app, 'Example: Layout-BS3', base_template='layout.html', template_mode='bootstrap3')
# Add views # Add views
admin.add_view(UserAdmin(User, db.session)) admin.add_view(UserAdmin(User, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
This example shows how to customize Flask-Admin layout and overall look and feel. This example shows how you can customize the look & feel of the admin interface. This is done by overriding some of the built-in templates.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/layout/requirements.txt'
4. Run the application::
python examples/layout/app.py
The first time you run this example, a sample sqlite database gets populated automatically. To suppress this behaviour,
comment the following lines in app.py:::
if not os.path.exists(database_path):
build_sample_db()
...@@ -58,7 +58,7 @@ def index(): ...@@ -58,7 +58,7 @@ def index():
# Create admin with custom base template # Create admin with custom base template
admin = admin.Admin(app, base_template='layout.html') admin = admin.Admin(app, 'Example: Layout', base_template='layout.html')
# Add views # Add views
admin.add_view(UserAdmin(User, db.session)) admin.add_view(UserAdmin(User, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
External menu links example. This example shows how you can add links to external (non flask-admin) pages to the navbar menu, and how you can hide certain links if a user is not logged-in.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/menu-external-links/requirements.txt'
4. Run the application::
python examples/menu-external-links/app.py
...@@ -74,7 +74,7 @@ def load_user(user_id): ...@@ -74,7 +74,7 @@ def load_user(user_id):
if __name__ == '__main__': if __name__ == '__main__':
# Create admin interface # Create admin interface
admin = Admin() admin = Admin(name='Example: Menu')
admin.add_view(MyAdminView(name='Authenticated')) admin.add_view(MyAdminView(name='Authenticated'))
# Add home link by url # Add home link by url
......
Example which shows how to integrate Flask `MethodView` with Flask-Admin. Example which shows how to integrate Flask `MethodView` with Flask-Admin.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/methodview/requirements.txt'
4. Run the application::
python examples/methodview/app.py
...@@ -38,7 +38,7 @@ def index(): ...@@ -38,7 +38,7 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
# Create admin interface # Create admin interface
admin = admin.Admin() admin = admin.Admin(name="Example: MethodView")
admin.add_view(ViewWithMethodViews()) admin.add_view(ViewWithMethodViews())
admin.init_app(app) admin.init_app(app)
......
MongoEngine model backend integration. MongoEngine model backend integration.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/mongoengine/requirements.txt'
4. Run the application::
python examples/mongoengine/app.py
...@@ -119,7 +119,7 @@ def index(): ...@@ -119,7 +119,7 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, 'Example: MongoEngine')
# Add views # Add views
admin.add_view(UserView(User)) admin.add_view(UserView(User))
......
Flask
Flask-Admin
Flask-MongoEngine
Flask-Login
This example shows how to create two separate instances of Flask-Admin for one Flask application. This example shows how to create two separate instances of Flask-Admin for one Flask application.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/multi/requirements.txt'
4. Run the application::
python examples/multi/app.py
Peewee model backend integration example. Peewee model backend integration example.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/peewee/requirements.txt'
4. Run the application::
python examples/peewee/app.py
...@@ -83,7 +83,7 @@ if __name__ == '__main__': ...@@ -83,7 +83,7 @@ if __name__ == '__main__':
logging.basicConfig() logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
admin = admin.Admin(app, 'Peewee Models') admin = admin.Admin(app, name='Example: Peewee')
admin.add_view(UserAdmin(User)) admin.add_view(UserAdmin(User))
admin.add_view(PostAdmin(Post)) admin.add_view(PostAdmin(Post))
......
Flask
Flask-Admin
peewee
wtf-peewee
PyMongo model backend integration example. PyMongo model backend integration example.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/pymongo/requirements.txt'
4. Run the application::
python examples/pymongo/app.py
...@@ -114,7 +114,7 @@ def index(): ...@@ -114,7 +114,7 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, name='Example: PyMongo')
# Add views # Add views
admin.add_view(UserView(db.user, 'User')) admin.add_view(UserView(db.user, 'User'))
......
Flask
Flask-Admin
pymongo==2.4.1
bson
Simple Flask-Admin examples used by the quickstart tutorial. Simple Flask-Admin examples used by the quickstart tutorial.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/quickstart/requirements.txt'
4. Run the application with any of the following::
python examples/quickstart/app.py
python examples/quickstart/app2.py
python examples/quickstart/app3.py
...@@ -5,7 +5,7 @@ from flask.ext.admin import Admin ...@@ -5,7 +5,7 @@ from flask.ext.admin import Admin
app = Flask(__name__) app = Flask(__name__)
app.debug = True app.debug = True
admin = Admin(app) admin = Admin(app, name="Example: Quickstart")
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -10,7 +10,7 @@ class MyView(BaseView): ...@@ -10,7 +10,7 @@ class MyView(BaseView):
app = Flask(__name__) app = Flask(__name__)
app.debug = True app.debug = True
admin = Admin(app) admin = Admin(app, name="Example: Quickstart2")
admin.add_view(MyView(name='Hello')) admin.add_view(MyView(name='Hello'))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -10,7 +10,7 @@ class MyView(BaseView): ...@@ -10,7 +10,7 @@ class MyView(BaseView):
app = Flask(__name__) app = Flask(__name__)
app.debug = True app.debug = True
admin = Admin(app) admin = Admin(app, name="Example: Quickstart3")
admin.add_view(MyView(name='Hello 1', endpoint='test1', category='Test')) admin.add_view(MyView(name='Hello 1', endpoint='test1', category='Test'))
admin.add_view(MyView(name='Hello 2', endpoint='test2', category='Test')) admin.add_view(MyView(name='Hello 2', endpoint='test2', category='Test'))
admin.add_view(MyView(name='Hello 3', endpoint='test3', category='Test')) admin.add_view(MyView(name='Hello 3', endpoint='test3', category='Test'))
......
This example shows how to set up a Flask-Admin view as a Redis terminal.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/rediscli/requirements.txt'
4. Run the application::
python examples/rediscli/app.py
You should now be able to access a Redis instance on your machine (if it is running) through the admin interface.
\ No newline at end of file
...@@ -17,7 +17,7 @@ def index(): ...@@ -17,7 +17,7 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
# Create admin interface # Create admin interface
admin = admin.Admin(app) admin = admin.Admin(app, name="Example: Redis")
admin.add_view(rediscli.RedisCli(Redis())) admin.add_view(rediscli.RedisCli(Redis()))
# Start app # Start app
......
from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.serving import run_simple
from index.index import app as index
import examples.simple.simple
import examples.sqla.simple
import examples.layout.simple
import examples.forms.simple
import examples.auth.auth
examples.sqla.simple.build_sample_db()
examples.layout.simple.build_sample_db()
examples.forms.simple.build_sample_db()
examples.auth.auth.build_sample_db()
application = DispatcherMiddleware(
index,
{
'/simple': examples.simple.simple.app,
'/sqla/simple': examples.sqla.simple.app,
'/layout': examples.layout.simple.app,
'/forms': examples.forms.simple.app,
'/auth': examples.auth.auth.app,
}
)
if __name__ == '__main__':
run_simple('localhost', 5000, application,
use_reloader=True, use_debugger=True, use_evalex=True)
\ No newline at end of file
This example shows how to add some simple views to your admin interface.
The views do not have to be associated to any of your models, and you can fill them with whatever content you want.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/simple/requirements.txt'
4. Run the application::
python examples/simple/app.py
...@@ -30,9 +30,9 @@ def index(): ...@@ -30,9 +30,9 @@ def index():
return '<a href="/admin/">Click me to get to Admin!</a>' return '<a href="/admin/">Click me to get to Admin!</a>'
# Create admin interface # Create admin interface
admin = admin.Admin() admin = admin.Admin(name="Example: Simple Views")
admin.add_view(MyAdminView(category='Test')) admin.add_view(MyAdminView(name="view1", category='Test'))
admin.add_view(AnotherAdminView(category='Test')) admin.add_view(AnotherAdminView(name="view2", category='Test'))
admin.init_app(app) admin.init_app(app)
if __name__ == '__main__': if __name__ == '__main__':
......
{% extends 'admin/master.html' %} {% extends 'admin/master.html' %}
{% block body %} {% block body %}
{{ super() }} {{ super() }}
<div class="row col-md-10 col-md-offset-1"> <div class="row">
<h1>Flask-Admin example</h1> <div class="span10 offset1">
<p class="lead"> <h1>Flask-Admin example</h1>
Simple admin views, not related to models. <p class="lead">
</p> Simple admin views, not related to models.
<p> </p>
This example shows how to add your own views to the admin interface. The views do not have to be associated <p>
to any of your models, and you can fill them with whatever content you want. This example shows how to add your own views to the admin interface. The views do not have to be associated
</p> to any of your models, and you can fill them with whatever content you want.
<p> </p>
By adding custom views to the admin interface, they become accessible through the <em>navbar</em> at the top. <p>
</p> By adding custom views to the admin interface, they become accessible through the <em>navbar</em> at the top.
<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a> </p>
<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a>
</div>
</div> </div>
{% endblock body %} {% endblock body %}
This example shows how to use inline forms when working with related models.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/sqla-inline/requirements.txt'
4. Run the application::
python examples/sqla-inline/app.py
...@@ -118,7 +118,7 @@ if __name__ == '__main__': ...@@ -118,7 +118,7 @@ if __name__ == '__main__':
pass pass
# Create admin # Create admin
admin = admin.Admin(app, 'Inline Fun') admin = admin.Admin(app, name='Example: Inline Models')
# Add views # Add views
admin.add_view(LocationAdmin()) admin.add_view(LocationAdmin())
......
Flask
Flask-Admin
Flask-SQLAlchemy
WTForms==1.0.5
SQLAlchemy model backend integration examples. SQLAlchemy model backend integration examples.
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/sqla/requirements.txt'
4. Run either of these applications::
python examples/sqla/app.py
python examples/sqla/app2.py
The first time you run this example, a sample sqlite database gets populated automatically. To suppress this behaviour,
comment the following lines in app.py:::
if not os.path.exists(database_path):
build_sample_db()
...@@ -144,7 +144,7 @@ class TreeView(sqla.ModelView): ...@@ -144,7 +144,7 @@ class TreeView(sqla.ModelView):
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, name='Example: SQLAlchemy')
# Add views # Add views
admin.add_view(UserAdmin(User, db.session)) admin.add_view(UserAdmin(User, db.session))
......
...@@ -50,7 +50,7 @@ class TyreAdmin(sqla.ModelView): ...@@ -50,7 +50,7 @@ class TyreAdmin(sqla.ModelView):
form_columns = ['car', 'tyre_id', 'desc'] form_columns = ['car', 'tyre_id', 'desc']
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, name='Example: SQLAlchemy2')
admin.add_view(CarAdmin(Car, db.session)) admin.add_view(CarAdmin(Car, db.session))
admin.add_view(TyreAdmin(Tyre, db.session)) admin.add_view(TyreAdmin(Tyre, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
{% extends 'admin/master.html' %} {% extends 'admin/master.html' %}
{% block body %} {% block body %}
{{ super() }} {{ super() }}
<div class="row col-md-10 col-md-offset-1"> <div class="row">
<div class="span10 offset1">
<h1>Flask-Admin example</h1> <h1>Flask-Admin example</h1>
<p class="lead"> <p class="lead">
Basic SQLAlchemy model views. Basic SQLAlchemy model views.
</p> </p>
<p> <p>
This example shows how to add basic CRUD-views for your SQLAlchemy models. This example shows how to add basic CRUD-views for your SQLAlchemy models.
</p> </p>
<p> <p>
The views are generated automatically, but it is perfectly possible to customize them to suit your needs. The views are generated automatically, but it is perfectly possible to customize them to suit your needs.
</p> </p>
<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a> <a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a>
</div>
</div> </div>
{% endblock body %} {% endblock body %}
Simple CKEditor integration example. This example shows how you can turn a TextArea field into a rich WYSIWYG editor using WTForms and CKEditor.
\ No newline at end of file
To run this example:
1. Clone the repository::
git clone https://github.com/mrjoes/flask-admin.git
cd flask-admin
2. Create and activate a virtual environment::
virtualenv env
source env/bin/activate
3. Install requirements::
pip install -r 'examples/wysiwyg/requirements.txt'
4. Run the application::
python examples/wysiwyg/app.py
...@@ -13,7 +13,7 @@ app = Flask(__name__) ...@@ -13,7 +13,7 @@ app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790' app.config['SECRET_KEY'] = '123456790'
# Create in-memory database # Create in-memory database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dummy.sqlite' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sample_db.sqlite'
app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app) db = SQLAlchemy(app)
...@@ -55,7 +55,7 @@ def index(): ...@@ -55,7 +55,7 @@ def index():
if __name__ == '__main__': if __name__ == '__main__':
# Create admin # Create admin
admin = admin.Admin(app) admin = admin.Admin(app, name="Example: WYSIWYG")
# Add views # Add views
admin.add_view(PageAdmin(Page, db.session)) admin.add_view(PageAdmin(Page, db.session))
......
Flask
Flask-Admin
Flask-SQLAlchemy
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