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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현