How to import blueprints with the same name as the file they are in?How to merge two dictionaries in a single expression?How do I check if a list is empty?How to import a module given the full path?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How do I sort a dictionary by value?How to import other Python files?How do I list all files of a directory?How to read a file line-by-line into a list?Importing files from different folder

Is it recommended against to open-source the code of a webapp?

Complex sentence - words lacking?

Why doesn’t a normal window produce an apparent rainbow?

What's the correct term for a waitress in the Middle Ages?

Where does this pattern of naming products come from?

Why don't B747s start takeoffs with full throttle?

What LISP compilers and interpreters were available for 8-bit machines?

Can an Eldritch Knight use Action Surge and thus Arcane Charge even when surprised?

PL/SQL function to receive a number and return its binary format

Select items in a list that contain criteria #2

What does the "c." listed under weapon length mean?

How did students remember what to practise between lessons without any sheet music?

Why only the fundamental frequency component is said to give useful power?

Is it possible to express disjunction through conjunction and implication?

Why is the relationship between frequency and pitch exponential?

Etymology of 'calcit(r)are'?

Why is the application of an oracle function not a measurement?

Average spam confidence

Building a road to escape Earth's gravity by making a pyramid on Antartica

Translating 'Liber'

Can you really not move between grapples/shoves?

Russian equivalents of "no love lost"

Strange symbol for two functions

Why does Kathryn say this in 12 Monkeys?



How to import blueprints with the same name as the file they are in?


How to merge two dictionaries in a single expression?How do I check if a list is empty?How to import a module given the full path?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How do I sort a dictionary by value?How to import other Python files?How do I list all files of a directory?How to read a file line-by-line into a list?Importing files from different folder






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















Background



I'm trying to set up a blueprint whose name matches the filename it resides in, so that when I reference it in my app.py I know where the blueprint comes from. This should be possible because the example on exploreflask uses the same pattern. Still, I cannot figure out how to make this work with my structure.



File structure



├── app.py
├── frontend
   ├── __init__.py
   └── views
   ├── home.py
   └── __init__.py


Example



frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)
home1 = Blueprint('home1', __name__)


frontend/views/__init__.py



from .home import home
from .home import home1


app.py



from flask import Flask

from frontend.views import home
from frontend.views import home1

print (type(home)) --> <class 'function'>
print (type(home1)) --> <class 'flask.blueprints.Blueprint'>


As home1 registers correctly as a Blueprint but home does not I suspect that
there is a name collision but I don't know how to resolve it despite looking into
this excellent article on importing conventions.



As a result, when I try to register my blueprints with the app
this will work:



app.register_blueprint(home1, url_prefix='/home1') --> Fine


but this won't:



app.register_blueprint(home, url_prefix='/home')
--> AttributeError: 'function' object has no attribute 'name'


Why not just go along with using home1?



  1. I want to understand how the collision can be resolved

  2. I want to be able to use route names that are the same as the filename they are in like so:

frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)

@home.route('/')
def home():
pass









share|improve this question
























  • Are you trying to use the Divisional or Functional structure described in exporeflask?

    – PGHE
    Mar 25 at 0:12

















-1















Background



I'm trying to set up a blueprint whose name matches the filename it resides in, so that when I reference it in my app.py I know where the blueprint comes from. This should be possible because the example on exploreflask uses the same pattern. Still, I cannot figure out how to make this work with my structure.



File structure



├── app.py
├── frontend
   ├── __init__.py
   └── views
   ├── home.py
   └── __init__.py


Example



frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)
home1 = Blueprint('home1', __name__)


frontend/views/__init__.py



from .home import home
from .home import home1


app.py



from flask import Flask

from frontend.views import home
from frontend.views import home1

print (type(home)) --> <class 'function'>
print (type(home1)) --> <class 'flask.blueprints.Blueprint'>


As home1 registers correctly as a Blueprint but home does not I suspect that
there is a name collision but I don't know how to resolve it despite looking into
this excellent article on importing conventions.



As a result, when I try to register my blueprints with the app
this will work:



app.register_blueprint(home1, url_prefix='/home1') --> Fine


but this won't:



app.register_blueprint(home, url_prefix='/home')
--> AttributeError: 'function' object has no attribute 'name'


Why not just go along with using home1?



  1. I want to understand how the collision can be resolved

  2. I want to be able to use route names that are the same as the filename they are in like so:

frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)

@home.route('/')
def home():
pass









share|improve this question
























  • Are you trying to use the Divisional or Functional structure described in exporeflask?

    – PGHE
    Mar 25 at 0:12













-1












-1








-1








Background



I'm trying to set up a blueprint whose name matches the filename it resides in, so that when I reference it in my app.py I know where the blueprint comes from. This should be possible because the example on exploreflask uses the same pattern. Still, I cannot figure out how to make this work with my structure.



File structure



├── app.py
├── frontend
   ├── __init__.py
   └── views
   ├── home.py
   └── __init__.py


Example



frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)
home1 = Blueprint('home1', __name__)


frontend/views/__init__.py



from .home import home
from .home import home1


app.py



from flask import Flask

from frontend.views import home
from frontend.views import home1

print (type(home)) --> <class 'function'>
print (type(home1)) --> <class 'flask.blueprints.Blueprint'>


As home1 registers correctly as a Blueprint but home does not I suspect that
there is a name collision but I don't know how to resolve it despite looking into
this excellent article on importing conventions.



As a result, when I try to register my blueprints with the app
this will work:



app.register_blueprint(home1, url_prefix='/home1') --> Fine


but this won't:



app.register_blueprint(home, url_prefix='/home')
--> AttributeError: 'function' object has no attribute 'name'


Why not just go along with using home1?



  1. I want to understand how the collision can be resolved

  2. I want to be able to use route names that are the same as the filename they are in like so:

frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)

@home.route('/')
def home():
pass









share|improve this question
















Background



I'm trying to set up a blueprint whose name matches the filename it resides in, so that when I reference it in my app.py I know where the blueprint comes from. This should be possible because the example on exploreflask uses the same pattern. Still, I cannot figure out how to make this work with my structure.



File structure



├── app.py
├── frontend
   ├── __init__.py
   └── views
   ├── home.py
   └── __init__.py


Example



frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)
home1 = Blueprint('home1', __name__)


frontend/views/__init__.py



from .home import home
from .home import home1


app.py



from flask import Flask

from frontend.views import home
from frontend.views import home1

print (type(home)) --> <class 'function'>
print (type(home1)) --> <class 'flask.blueprints.Blueprint'>


As home1 registers correctly as a Blueprint but home does not I suspect that
there is a name collision but I don't know how to resolve it despite looking into
this excellent article on importing conventions.



As a result, when I try to register my blueprints with the app
this will work:



app.register_blueprint(home1, url_prefix='/home1') --> Fine


but this won't:



app.register_blueprint(home, url_prefix='/home')
--> AttributeError: 'function' object has no attribute 'name'


Why not just go along with using home1?



  1. I want to understand how the collision can be resolved

  2. I want to be able to use route names that are the same as the filename they are in like so:

frontend/views/home.py



from flask import Blueprint, render_template

home = Blueprint('home', __name__)

@home.route('/')
def home():
pass






python flask python-import






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 16:28







pfabri

















asked Mar 24 at 15:34









pfabripfabri

136112




136112












  • Are you trying to use the Divisional or Functional structure described in exporeflask?

    – PGHE
    Mar 25 at 0:12

















  • Are you trying to use the Divisional or Functional structure described in exporeflask?

    – PGHE
    Mar 25 at 0:12
















Are you trying to use the Divisional or Functional structure described in exporeflask?

– PGHE
Mar 25 at 0:12





Are you trying to use the Divisional or Functional structure described in exporeflask?

– PGHE
Mar 25 at 0:12












1 Answer
1






active

oldest

votes


















-1














Try to use Capital letters in the Blueprint Module.



also you can use the url_prefix in the module.



Home = Blueprint("Home", __name__, url_prefix="/home")

@Home.route("/")
def home():
pass





share|improve this answer

























  • Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

    – pfabri
    Mar 24 at 16:11












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325440%2fhow-to-import-blueprints-with-the-same-name-as-the-file-they-are-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














Try to use Capital letters in the Blueprint Module.



also you can use the url_prefix in the module.



Home = Blueprint("Home", __name__, url_prefix="/home")

@Home.route("/")
def home():
pass





share|improve this answer

























  • Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

    – pfabri
    Mar 24 at 16:11
















-1














Try to use Capital letters in the Blueprint Module.



also you can use the url_prefix in the module.



Home = Blueprint("Home", __name__, url_prefix="/home")

@Home.route("/")
def home():
pass





share|improve this answer

























  • Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

    – pfabri
    Mar 24 at 16:11














-1












-1








-1







Try to use Capital letters in the Blueprint Module.



also you can use the url_prefix in the module.



Home = Blueprint("Home", __name__, url_prefix="/home")

@Home.route("/")
def home():
pass





share|improve this answer















Try to use Capital letters in the Blueprint Module.



also you can use the url_prefix in the module.



Home = Blueprint("Home", __name__, url_prefix="/home")

@Home.route("/")
def home():
pass






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 16:16

























answered Mar 24 at 15:59









JoySalomonJoySalomon

15




15












  • Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

    – pfabri
    Mar 24 at 16:11


















  • Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

    – pfabri
    Mar 24 at 16:11

















Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

– pfabri
Mar 24 at 16:11






Using capital letters could be a hacky workaround, but that's exactly what I'd like to avoid. Besides it violates PEP8: capitals are for classes. The url_prefix is unrelated to the problem (and I'm using it already, anyway).

– pfabri
Mar 24 at 16:11


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325440%2fhow-to-import-blueprints-with-the-same-name-as-the-file-they-are-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript