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;
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?
- I want to understand how the collision can be resolved
- 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
add a comment |
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?
- I want to understand how the collision can be resolved
- 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
Are you trying to use the Divisional or Functional structure described in exporeflask?
– PGHE
Mar 25 at 0:12
add a comment |
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?
- I want to understand how the collision can be resolved
- 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
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?
- I want to understand how the collision can be resolved
- 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
python flask python-import
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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. Theurl_prefix
is unrelated to the problem (and I'm using it already, anyway).
– pfabri
Mar 24 at 16:11
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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. Theurl_prefix
is unrelated to the problem (and I'm using it already, anyway).
– pfabri
Mar 24 at 16:11
add a comment |
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
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. Theurl_prefix
is unrelated to the problem (and I'm using it already, anyway).
– pfabri
Mar 24 at 16:11
add a comment |
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
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
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. Theurl_prefix
is unrelated to the problem (and I'm using it already, anyway).
– pfabri
Mar 24 at 16:11
add a comment |
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. Theurl_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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Are you trying to use the Divisional or Functional structure described in exporeflask?
– PGHE
Mar 25 at 0:12