Fix issue where redirecting to endpoints page would only show table
This commit is contained in:
34
app.py
34
app.py
@@ -535,18 +535,6 @@ def plot_query(query_id):
|
||||
return plot_div
|
||||
|
||||
def get_routes():
|
||||
|
||||
return routes
|
||||
|
||||
@app.route('/endpoints')
|
||||
def list_endpoints():
|
||||
"""
|
||||
Lists all API endpoints available in the Flask application.
|
||||
|
||||
This endpoint retrieves all registered routes, excluding static routes,
|
||||
and displays their details such as endpoint name, URL, allowed HTTP methods,
|
||||
view function name, and a brief description.
|
||||
"""
|
||||
routes = []
|
||||
for rule in app.url_map.iter_rules():
|
||||
if rule.endpoint == 'static':
|
||||
@@ -560,7 +548,26 @@ def list_endpoints():
|
||||
'doc': app.view_functions[rule.endpoint].__doc__
|
||||
}
|
||||
routes.append(route_info)
|
||||
return routes
|
||||
|
||||
@app.route('/endpoints')
|
||||
def list_endpoints():
|
||||
"""
|
||||
Lists all API endpoints available in the Flask application.
|
||||
|
||||
This endpoint retrieves all registered routes, excluding static routes,
|
||||
and displays their details such as endpoint name, URL, allowed HTTP methods,
|
||||
view function name, and a brief description.
|
||||
"""
|
||||
routes = get_routes()
|
||||
|
||||
if htmx:
|
||||
return render_block(app.jinja_env, 'endpoints.html', 'content', routes=routes)
|
||||
return render_template('endpoints.html', routes=routes)
|
||||
|
||||
@app.route('/endpoints/search')
|
||||
def search_endpoints():
|
||||
routes = get_routes()
|
||||
search = request.args.get('search', '').lower()
|
||||
if search:
|
||||
routes = [
|
||||
@@ -572,11 +579,8 @@ def list_endpoints():
|
||||
or (route['doc'] and search in route['doc'].lower())
|
||||
]
|
||||
|
||||
if htmx:
|
||||
return render_template('partials/endpoints_table.html', routes=routes)
|
||||
|
||||
return render_template('endpoints.html', routes=routes)
|
||||
|
||||
@app.teardown_appcontext
|
||||
def closeConnection(exception):
|
||||
db.close_connection()
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<!-- Optional: Search or Filter functionality with HTMX -->
|
||||
<div class="mb-4">
|
||||
<input type="text" id="search" name="search" placeholder="Search endpoints..."
|
||||
class="w-full p-2 border border-gray-300 rounded" hx-get="/endpoints"
|
||||
class="w-full p-2 border border-gray-300 rounded" hx-get="{{ url_for('search_endpoints') }}"
|
||||
hx-trigger="keyup changed delay:500ms, search" hx-push-url="true" hx-target="#endpoints-table"
|
||||
hx-include="[name='search']">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user