[Flask] Subscribe Mail

Yabin Zhang ybzhang2015 at gmail.com
Tue Mar 20 13:14:02 EDT 2018



Sent from Mailspring (https://getmailspring.com/), the best free email app for work
On Mar 20 2018, at 12:00 am, flask-request at python.org wrote:
>
> Send Flask mailing list submissions to
> flask at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/flask
> or, via email, send a message with subject or body 'help' to
> flask-request at python.org
>
> You can reach the person managing the list at
> flask-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Flask digest..."
>
>
> Today's Topics:
> 1. Re: Blueprints templates (Laura Morales)
> 2. Re: Blueprints templates (Laura Morales)
>
>
> ----------------------------------------------------------------------
> Message: 1
> Date: Sun, 18 Mar 2018 20:15:33 +0100
> From: "Laura Morales" <lauretas at mail.com>
> To: "Jerry Mccreary" <jerry.mccreary at mac.com>
> Cc: flask at python.org
> Subject: Re: [Flask] Blueprints templates
> Message-ID:
> <trinity-171d3a92-ac94-4316-8fea-0b87ead1d1f1-1521400533808 at 3c-app-mailcom-lxa13>
>
> Content-Type: text/plain; charset=UTF-8
> > The Flask project has a main ?templates? folder. The convenience of
> > blueprints it that the blueprint folder can have the same structure
> > as the main templates folder. ?When a view is rendered with
> > `render_template()`, it will first look in the blueprint?s template
> > folder for the specified template, if doesn?t find it, then it looks
> > in the main template folder.
>
>
> I think the documentation says the opposite. First it looks in the main templates folder, and if it doesn't find it then it looks inside the blueprints folders (from the first registered up to the last one). That's why they suggest to add this extra folder in your blueprints templates directory. And that's why I think it would be nice if Flask could automatically understand what blueprint I'm talking about without creating the extra folder.
>
> ------------------------------
> Message: 2
> Date: Sun, 18 Mar 2018 20:54:37 +0100
> From: "Laura Morales" <lauretas at mail.com>
> To: "Jerry Mccreary" <jerry.mccreary at mac.com>
> Cc: flask at python.org
> Subject: Re: [Flask] Blueprints templates
> Message-ID:
> <trinity-5ac337af-9150-4715-9784-fd935c9d20a9-1521402877442 at 3c-app-mailcom-lxa13>
>
> Content-Type: text/plain; charset=UTF-8
> I've found this old issue that's basically the same thing https://github.com/pallets/flask/issues/266
> I think it would be useful to have an option to trigger this behavior.
> ?
> ?
>
> Sent:?Sunday, March 18, 2018 at 7:44 PM
> From:?"Jerry Mccreary" <jerry.mccreary at mac.com>
> To:?"Laura Morales" <lauretas at mail.com>
> Cc:?flask at python.org
> Subject:?Re: [Flask] Blueprints templates
>
> I don?t think it is a hack, as much as it is how the operating system/python works.
> ?
> The Flask project has a main ?templates? folder. The convenience of blueprints it that the blueprint folder
> can have the same structure as the main templates folder. ?When a view is rendered with `render_template()`,
> it will first look in the blueprint?s template folder for the specified template, if doesn?t find it, then it looks in the main template folder.
> (If I?m wrong, someone please correct me).
> ?
> This is similar scenario of how python packages are referenced in a project. Your Flask app will first look in the project folder for a reference module,
> then, if not finding it, will look in the installed packages.
> ?
> Flask is not going to assume that a blueprint?s templates are in folder that happens to have the same name as the blueprint.
> (I?m not sure if that would be desirable to have as an automatic assumption)
> ?
> See where I referenced setting the template_folder parameter here: http://flask.pocoo.org/docs/0.12/blueprints/#my-first-blueprint?
>
> ??
> On Mar 18, 2018, at 2:29 PM, Laura Morales <lauretas at mail.com[mailto:lauretas at mail.com]> wrote:?
> Yes I'd like to divide my websites into 2 modules (blueprints), developed by two separate groups. So, each blueprint will contain its own templates, views, static assets etc.
> Right now I use "module-1/templates/module-1/template.html" but it looks a bit hackish. I was hoping there was a way to remove the need of the inner "module-1" folder, and have Flask instead automatically recognize that "module-1/template.html" is actually "template.html" inside "module-1/templates/".
> ?the blueprint using templates_folder attribute.
> By using this parameter, you point to the blueprint?s template directory
> once, and the associated views will look in that directory.
> Does this solve the problem with different blueprints having a template with the same name?
> ?
> ?
>
> Sent:?Sunday, March 18, 2018 at 7:07 PM
> From:?"Jerry Mccreary" <jerry.mccreary at mac.com[mailto:jerry.mccreary at mac.com]>
> To:?"Laura Morales" <lauretas at mail.com[mailto:lauretas at mail.com]>
> Cc:?flask at python.org[mailto:flask at python.org]
> Subject:?Re: [Flask] Blueprints templates
>
> I?m not sure if this answers your question:
> ?
> The structure you reference is for project and maintenance organization, keeping blueprint assets together.
> Blueprints can also go in the main templates folder at root of project.
> ?
> Ex:
> yourpackage/
> blueprints/
> admin/
> __init__.py
> models.py
> views.py
> ?
> templates/ ?(main templates folder)
> admin/
> index.html
> blueprint2/
> index.html?
> blueprint3/
> index.html
>
> ?
> The subfolders are used because blueprints may have templates named the same.
> For example, if all the templates were in a single directory, they would need to be name without conflict.
> ?
> yourpackage/
> blueprints/
> etc.
> ?
> templates/ (main templates folder)
> admin_index.html
> blueprint1_index.html
> blueprint2_index.html
> blueprint3_index.html
> ?
> Also, when defining the a blueprint, the corresponding template can be defined when declaring the blueprint using templates_folder attribute.
> By using this parameter, you point to the blueprint?s template directory once, and the associated views will look in that directory.
>
>
> ------------------------------
> Subject: Digest Footer
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
>
> ------------------------------
> End of Flask Digest, Vol 33, Issue 19
> *************************************
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20180321/39e4e293/attachment.html>


More information about the Flask mailing list