У меня странное поведение, которое я вижу в своем приложении flask, где я генерирую URL-адрес только для одного представления, чтобы оно вызывало другое представление. Пытался отследить проблему, но не могу понять, как это сделать.
Вот представления классов:
@admin_blueprint.route('/admin/<string:manage_admins>', methods=['GET', 'POST'])
@login_required
@fresh_login_required
def admin_manage_admins(manage_admins, admin_id=None):
"""
Used to managed all the registered
admins by the super admin or the developer
"""
# TODO finish this
admin = Admin()
form = AllAdminsProfile(object=admin)
include_name = 'manage_admins'
admins = Admin.query.all()
if form.validate_on_submit():
try:
# TODO update the edited admin using 'id'
return redirect(url_for('admin.admin', admin_id=admin_id))
except TemplateError as err:
print(err)
return render_template('admin.html', page_title='Admin Dashboard', dashboard_name='Haiflytrap Dashboard', include_name=include_name, form=form, admins=admins)
# INFO Optional route that might be included in the future
# @admin_blueprint.route('/admin/<string:customers_orders>', defaults={'order_id': ''}, methods=['GET', 'POST'])
@admin_blueprint.route('/admin/<string:customers_orders>', methods=['GET'])
@login_required
def customer_orders(customer_orders):
# order = CustomerOrder()
# form = OrderForm(object=order)
if customer_orders == 'customers_orders':
try:
orders = CustomerOrder.query.get()
include_name = 'customers_orders'
# if customers_orders_form.validate_on_submit():
# # TODO add query to update on item
# orders = CustomerOrder.query.get(order_id).first_or_404()
# customers_orders_form.populate_obj(object=orders)
# db.session.commit()
# return redirect(url_for('admin.admin'))
return render_template('admin.html', page_title='Admin Dashboard', dashboard_name='Haiflytrap Dashboard', include_name=include_name, orders=orders)
except TemplateError as err:
print(err)
Ссылка html, которая должна вызывать def customer_orders()
, но она вызывает def admin_manage_admins()
вместо:
<a href="{{ url_for('admin.customer_orders', customers_orders='customers_orders') }}" class="list-group-item list-group-item-action my-btn-secondary">Customer Orders</a>
И этот шаблон admin.html
используется:
{% extends 'admin_layout.html' %}
{% block content %}
{% if include_name == 'dashboard' %}
{% include 'dash_landing.html' %}
{% endif %}
{% if include_name == 'manage_admins' %}
{% include 'manage_admin.html' %}
{% endif %}
{% if include_name == 'profile' %}
{% include 'profile.html' %}
{% endif %}
{% if include_name == 'password_update' %}
{% include 'password_update.html' %}
{% endif %}
{% if include_name == 'customers_orders' %}
{% include 'customers_orders.html' %}
{% endif %}
{% endblock content %}