Answer the question
In order to leave comments, you need to log in
Blueprint add_url_rule not working in flask?
Hello,
there is an application in the cortex that connects the blueprint
, the blueprint itself is initialized in another file like this
app.register_blueprint(admin, url_prefix='/admin')
admin = Blueprint('admin', __name__,
template_folder='admin')
from control import app
from maincontroller import main
from admin.acontrol import admin
from admin.controllers.main import AdminMain
# route section
# ======================================
app.add_url_rule('/',view_func=main.as_view("main"))
admin.add_url_rule('/',view_func=AdminMain.as_view("adminrmain"))
Answer the question
In order to leave comments, you need to log in
It should work, maybe it has something to do with the class-based views you are using?
views are absolutely standard from the documentation
# -*- coding: utf-8 -*-
from flask import render_template, request, redirect, url_for, session
from flask.views import MethodView
class AdminMain(MethodView):
def post(self):
return render_template('adminindex.html')
def get(self):
return render_template('adminindex.html')
and if you create a separate file with routes in the blueprint folder, and then import this file into the file where the application is created and launched, then everything is fine, damn magic. it turns out that if the routes for the blueprint are written in the same place as for the main application, he doesn’t want to do anything, but if you put it in a separate file and do everything the same as with the file with sonny routes, then it works ....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question