Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
ada08860
Commit
ada08860
authored
Dec 11, 2014
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve AdminIndexView docs, prevent breaking static files when url='/'
parent
50de6ff0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
base.py
flask_admin/base.py
+20
-2
test_base.py
flask_admin/tests/test_base.py
+11
-1
No files found.
flask_admin/base.py
View file @
ada08860
...
...
@@ -229,10 +229,16 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
if
not
self
.
url
.
startswith
(
'/'
):
self
.
url
=
'
%
s/
%
s'
%
(
self
.
admin
.
url
,
self
.
url
)
# If we're working from the root of the site, set prefix to None
if
self
.
url
==
'/'
:
self
.
url
=
None
# prevent admin static files from conflicting with flask static files
if
not
self
.
static_url_path
:
self
.
static_folder
=
'static'
self
.
static_url_path
=
'/static/admin'
# If name is not povided, use capitalized endpoint name
if
self
.
name
is
None
:
self
.
name
=
self
.
_prettify_class_name
(
self
.
__class__
.
__name__
)
...
...
@@ -383,9 +389,21 @@ class AdminIndexView(BaseView):
@expose('/')
def index(self):
arg1 = 'Hello'
return
render_template('admin
home.html', arg1=arg1)
return
self.render('admin/my
home.html', arg1=arg1)
admin = Admin(index_view=MyHomeView())
Also, you can change the root url from /admin to / with the following::
admin = Admin(
app,
index_view=AdminIndexView(
name='Home',
template='admin/myhome.html',
url='/'
)
)
Default values for the index page are:
...
...
flask_admin/tests/test_base.py
View file @
ada08860
from
nose.tools
import
ok_
,
eq_
,
raises
from
flask
import
Flask
,
request
,
abort
from
flask
import
Flask
,
request
,
abort
,
url_for
from
flask.views
import
MethodView
from
flask.ext.admin
import
base
...
...
@@ -132,6 +132,11 @@ def test_admin_customizations():
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/foobar/'
)
eq_
(
rv
.
status_code
,
200
)
# test custom static_url_path
with
app
.
test_request_context
(
'/'
):
rv
=
client
.
get
(
url_for
(
'admin.static'
,
filename
=
'bootstrap/bootstrap2/css/bootstrap.css'
))
eq_
(
rv
.
status_code
,
200
)
def
test_baseview_registration
():
...
...
@@ -359,6 +364,11 @@ def test_root_mount():
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/mockview/'
)
eq_
(
rv
.
data
,
b
'Success!'
)
# test static files when url='/'
with
app
.
test_request_context
(
'/'
):
rv
=
client
.
get
(
url_for
(
'admin.static'
,
filename
=
'bootstrap/bootstrap2/css/bootstrap.css'
))
eq_
(
rv
.
status_code
,
200
)
def
test_menu_links
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment