M
M
Michael2014-04-13 16:18:42
Flask
Michael, 2014-04-13 16:18:42

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')


and now the question
is why for the main app application the add_url_rule function works, but not for the blueprint?

the route file looks like this

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"))

that is, in my opinion, the following should turn out, if we go to the root, the page is displayed / it spits out app.add_url_rule('/',view_func=main.as_view("main")) everything is fine here,
and if we go to /admin, then it should be spit out admin.add_url_rule('/',view_func=AdminMain.as_view("adminrmain"))
but nothing happens says page not found, nothing but 404 error is thrown to the console.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Y
Yuri Shikanov, 2014-04-13
@dizballanze

It should work, maybe it has something to do with the class-based views you are using?

M
Michael, 2014-04-13
@nextel

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')

M
Michael, 2014-04-13
@nextel

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 ....

M
MK, 2015-09-12
@vasIvas

true возвращается, это фича такая.
Аналогично записи

switch (length){
    case 1: 
    objects[1].call(context, params);
    return  true;
}

Фича в том, что возвращается последнее значение:
function a(){return 1,2,3,4,5;}
a() //вернёт 5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question