I'm in the middle of upgrading to 0.7. The upgrade script worked, but one
change is causing lots of issues is the change of template syntax.
I had a lot of this kind of thing all over the place:
return render_template('admin_base/index.html', user=user)
where 'admin_base' is the old name of the module but is now the name of the
Blueprint declared as:
admin_base = Blueprint('admin_base', __name__)
also everywhere I have inherited templates declared it is failing:
{% extends "admin_base/base.html" %}
looks like I have to remove the module names everywhere. Is that the easiest
way?
I have the same setup as you and I'm not having any issues. I did not have to remove the module/blueprint name. Could you provide more information, like what error you're actually getting? On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote: > I'm in the middle of upgrading to 0.7. The upgrade script worked, but one > change is causing lots of issues is the change of template syntax. > > I had a lot of this kind of thing all over the place: > > return render_template('admin_base/index.html', user=user) > > where 'admin_base' is the old name of the module but is now the name of the > Blueprint declared as: > > admin_base = Blueprint('admin_base', __name__) > > also everywhere I have inherited templates declared it is failing: > > {% extends "admin_base/base.html" %} > > looks like I have to remove the module names everywhere. Is that the > easiest way? >
Here's the blueprint declaration:
admin_base = Blueprint('admin_base', __name__, template_folder='templates')
Here's the view function:
@admin_base.route('/')
@login_required
def index():
user = None
if 'logged_in_user' in session:
user = Admin.find_by_email(session['logged_in_user'])
return render_template('admin_base/index.html', user=user)
and here's the error:
...
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/app.py",
line 1041, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 19,
in decorated_function
return f(*args, **kwargs)
File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 30,
in index
return render_template('admin_base/index.html', user=user)
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
line 122, in render_template
return _render(ctx.app.jinja_env.get_template(template_name),
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
line 716, in get_template
return self._load_template(name, self.make_globals(globals))
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
line 690, in _load_template
template = self.loader.load(self, name, globals)
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/loaders.py",
line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
line 61, in get_source
raise TemplateNotFound(template)
TemplateNotFound: admin_base/index.html
On Wed, Jun 29, 2011 at 10:46 AM, Adam Patterson <fakeempire@gmail.com>wrote:
> I have the same setup as you and I'm not having any issues. I did not have
> to remove the module/blueprint name.
>
> Could you provide more information, like what error you're actually
> getting?
>
>
> On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote:
>
>> I'm in the middle of upgrading to 0.7. The upgrade script worked, but one
>> change is causing lots of issues is the change of template syntax.
>>
>> I had a lot of this kind of thing all over the place:
>>
>> return render_template('admin_base/index.html', user=user)
>>
>> where 'admin_base' is the old name of the module but is now the name of
>> the Blueprint declared as:
>>
>> admin_base = Blueprint('admin_base', __name__)
>>
>> also everywhere I have inherited templates declared it is failing:
>>
>> {% extends "admin_base/base.html" %}
>>
>> looks like I have to remove the module names everywhere. Is that the
>> easiest way?
>>
>
>
Oh, here's how the blueprint gets added:
from jiffy.admin.login import admin_base
app.register_blueprint(admin_base, url_prefix="/admin")
On Wed, Jun 29, 2011 at 11:17 AM, Charlie Evett <charlieevett@litl.com>wrote:
> Here's the blueprint declaration:
>
> admin_base = Blueprint('admin_base', __name__, template_folder='templates')
>
> Here's the view function:
>
> @admin_base.route('/')
> @login_required
> def index():
> user = None
> if 'logged_in_user' in session:
> user = Admin.find_by_email(session['logged_in_user'])
> return render_template('admin_base/index.html', user=user)
>
> and here's the error:
>
> ...
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/app.py",
> line 1041, in dispatch_request
> return self.view_functions[rule.endpoint](**req.view_args)
> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 19,
> in decorated_function
> return f(*args, **kwargs)
> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 30,
> in index
> return render_template('admin_base/index.html', user=user)
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
> line 122, in render_template
> return _render(ctx.app.jinja_env.get_template(template_name),
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
> line 716, in get_template
> return self._load_template(name, self.make_globals(globals))
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
> line 690, in _load_template
> template = self.loader.load(self, name, globals)
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/loaders.py",
> line 115, in load
> source, filename, uptodate = self.get_source(environment, name)
> File
>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
> line 61, in get_source
> raise TemplateNotFound(template)
> TemplateNotFound: admin_base/index.html
>
>
> On Wed, Jun 29, 2011 at 10:46 AM, Adam Patterson <fakeempire@gmail.com>wrote:
>
>> I have the same setup as you and I'm not having any issues. I did not have
>> to remove the module/blueprint name.
>>
>> Could you provide more information, like what error you're actually
>> getting?
>>
>>
>> On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>
>>> I'm in the middle of upgrading to 0.7. The upgrade script worked, but one
>>> change is causing lots of issues is the change of template syntax.
>>>
>>> I had a lot of this kind of thing all over the place:
>>>
>>> return render_template('admin_base/index.html', user=user)
>>>
>>> where 'admin_base' is the old name of the module but is now the name of
>>> the Blueprint declared as:
>>>
>>> admin_base = Blueprint('admin_base', __name__)
>>>
>>> also everywhere I have inherited templates declared it is failing:
>>>
>>> {% extends "admin_base/base.html" %}
>>>
>>> looks like I have to remove the module names everywhere. Is that the
>>> easiest way?
>>>
>>
>>
>
Don't specify the template_folder in the Blueprint(). Flask knows to use the templates/ folder by default Just remove On Wed, Jun 29, 2011 at 10:54 AM, Charlie Evett <charlieevett@litl.com>wrote: > Oh, here's how the blueprint gets added: > > from jiffy.admin.login import admin_base > app.register_blueprint(admin_base, url_prefix="/admin") > > > On Wed, Jun 29, 2011 at 11:17 AM, Charlie Evett <charlieevett@litl.com>wrote: > >> Here's the blueprint declaration: >> >> admin_base = Blueprint('admin_base', __name__, >> template_folder='templates') >> >> Here's the view function: >> >> @admin_base.route('/') >> @login_required >> def index(): >> user = None >> if 'logged_in_user' in session: >> user = Admin.find_by_email(session['logged_in_user']) >> return render_template('admin_base/index.html', user=user) >> >> and here's the error: >> >> ... >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/app.py", >> line 1041, in dispatch_request >> return self.view_functions[rule.endpoint](**req.view_args) >> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 19, >> in decorated_function >> return f(*args, **kwargs) >> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line 30, >> in index >> return render_template('admin_base/index.html', user=user) >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py", >> line 122, in render_template >> return _render(ctx.app.jinja_env.get_template(template_name), >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py", >> line 716, in get_template >> return self._load_template(name, self.make_globals(globals)) >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py", >> line 690, in _load_template >> template = self.loader.load(self, name, globals) >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/loaders.py", >> line 115, in load >> source, filename, uptodate = self.get_source(environment, name) >> File >> "/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py", >> line 61, in get_source >> raise TemplateNotFound(template) >> TemplateNotFound: admin_base/index.html >> >> >> On Wed, Jun 29, 2011 at 10:46 AM, Adam Patterson <fakeempire@gmail.com>wrote: >> >>> I have the same setup as you and I'm not having any issues. I did not >>> have to remove the module/blueprint name. >>> >>> Could you provide more information, like what error you're actually >>> getting? >>> >>> >>> On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote: >>> >>>> I'm in the middle of upgrading to 0.7. The upgrade script worked, but >>>> one change is causing lots of issues is the change of template syntax. >>>> >>>> I had a lot of this kind of thing all over the place: >>>> >>>> return render_template('admin_base/index.html', user=user) >>>> >>>> where 'admin_base' is the old name of the module but is now the name of >>>> the Blueprint declared as: >>>> >>>> admin_base = Blueprint('admin_base', __name__) >>>> >>>> also everywhere I have inherited templates declared it is failing: >>>> >>>> {% extends "admin_base/base.html" %} >>>> >>>> looks like I have to remove the module names everywhere. Is that the >>>> easiest way? >>>> >>> >>> >> >
Hi, On 6/29/11 6:09 PM, Adam Patterson wrote: > Don't specify the template_folder in the Blueprint(). > > Flask knows to use the templates/ folder by default That is incorrect. Please check the documentation for the correct behavior. Each blueprint can have a template folder and the contents of this templates folder are added to the **searchpath**. That means you need to be explicit in this folder and add another folder in there: admin = Blueprint('admin', __name__, templates='templates') @admin.route('/') def index(): return render_template('admin/index.html') This means you need this structure: yourapplication/ admin/ templates/ admin/ index.html And *not* yourapplication/ admin/ templates/ index.html Regards, Armin
> > > Flask knows to use the templates/ folder by default > That is incorrect. Please check the documentation for the correct > behavior. Hey Armin! I don't have to specify the 'templates' folder in my app BUT my project layout is different from what you described. I use this. In this scenario flask knows to use the templates folder. Unless I'm missing something application/ views/ admin.py templates/ admin/ index.html
Hi, On 6/29/11 6:36 PM, Adam Patterson wrote: > I don't have to specify the 'templates' folder in my app BUT my project > layout is different from what you described. > > I use this. In this scenario flask knows to use the templates folder. > Unless I'm missing something That of course works just as well. In fact since 0.7 those two are doing exactly the same with the small difference that blueprint provided template paths have a lower priority than the one from the actual application. Regards, Armin
If I remove then I get the TemplateNotFound exception.
The only thing that works is -- no template name + specify template_folder
in constructor (also needs 'static_folder' since the template references a
static file.):
admin_base = Blueprint('admin_base', __name__, template_folder='templates',
static_folder="static")
...
@admin_base.route('/')
@login_required
def index():
user = None
if 'logged_in_user' in session:
user = Admin.find_by_email(session['logged_in_user'])
return render_template('index.html', user=user)
On Wed, Jun 29, 2011 at 12:09 PM, Adam Patterson <fakeempire@gmail.com>wrote:
> Don't specify the template_folder in the Blueprint().
>
> Flask knows to use the templates/ folder by default
>
>
> Just remove
> On Wed, Jun 29, 2011 at 10:54 AM, Charlie Evett <charlieevett@litl.com>wrote:
>
>> Oh, here's how the blueprint gets added:
>>
>> from jiffy.admin.login import admin_base
>> app.register_blueprint(admin_base, url_prefix="/admin")
>>
>>
>> On Wed, Jun 29, 2011 at 11:17 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>
>>> Here's the blueprint declaration:
>>>
>>> admin_base = Blueprint('admin_base', __name__,
>>> template_folder='templates')
>>>
>>> Here's the view function:
>>>
>>> @admin_base.route('/')
>>> @login_required
>>> def index():
>>> user = None
>>> if 'logged_in_user' in session:
>>> user = Admin.find_by_email(session['logged_in_user'])
>>> return render_template('admin_base/index.html', user=user)
>>>
>>> and here's the error:
>>>
>>> ...
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/app.py",
>>> line 1041, in dispatch_request
>>> return self.view_functions[rule.endpoint](**req.view_args)
>>> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line
>>> 19, in decorated_function
>>> return f(*args, **kwargs)
>>> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line
>>> 30, in index
>>> return render_template('admin_base/index.html', user=user)
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
>>> line 122, in render_template
>>> return _render(ctx.app.jinja_env.get_template(template_name),
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
>>> line 716, in get_template
>>> return self._load_template(name, self.make_globals(globals))
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
>>> line 690, in _load_template
>>> template = self.loader.load(self, name, globals)
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/loaders.py",
>>> line 115, in load
>>> source, filename, uptodate = self.get_source(environment, name)
>>> File
>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
>>> line 61, in get_source
>>> raise TemplateNotFound(template)
>>> TemplateNotFound: admin_base/index.html
>>>
>>>
>>> On Wed, Jun 29, 2011 at 10:46 AM, Adam Patterson <fakeempire@gmail.com>wrote:
>>>
>>>> I have the same setup as you and I'm not having any issues. I did not
>>>> have to remove the module/blueprint name.
>>>>
>>>> Could you provide more information, like what error you're actually
>>>> getting?
>>>>
>>>>
>>>> On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>>>
>>>>> I'm in the middle of upgrading to 0.7. The upgrade script worked, but
>>>>> one change is causing lots of issues is the change of template syntax.
>>>>>
>>>>> I had a lot of this kind of thing all over the place:
>>>>>
>>>>> return render_template('admin_base/index.html', user=user)
>>>>>
>>>>> where 'admin_base' is the old name of the module but is now the name of
>>>>> the Blueprint declared as:
>>>>>
>>>>> admin_base = Blueprint('admin_base', __name__)
>>>>>
>>>>> also everywhere I have inherited templates declared it is failing:
>>>>>
>>>>> {% extends "admin_base/base.html" %}
>>>>>
>>>>> looks like I have to remove the module names everywhere. Is that the
>>>>> easiest way?
>>>>>
>>>>
>>>>
>>>
>>
>
My apologies,
In my render_template() I specify the folder
render_template('admin_base/my_template.html')
On Wed, Jun 29, 2011 at 11:19 AM, Charlie Evett <charlieevett@litl.com>wrote:
> If I remove then I get the TemplateNotFound exception.
>
> The only thing that works is -- no template name + specify template_folder
> in constructor (also needs 'static_folder' since the template references a
> static file.):
>
> admin_base = Blueprint('admin_base', __name__, template_folder='templates',
> static_folder="static")
> ...
> @admin_base.route('/')
> @login_required
> def index():
> user = None
> if 'logged_in_user' in session:
> user = Admin.find_by_email(session['logged_in_user'])
> return render_template('index.html', user=user)
>
>
>
> On Wed, Jun 29, 2011 at 12:09 PM, Adam Patterson <fakeempire@gmail.com>wrote:
>
>> Don't specify the template_folder in the Blueprint().
>>
>> Flask knows to use the templates/ folder by default
>>
>>
>> Just remove
>> On Wed, Jun 29, 2011 at 10:54 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>
>>> Oh, here's how the blueprint gets added:
>>>
>>> from jiffy.admin.login import admin_base
>>> app.register_blueprint(admin_base, url_prefix="/admin")
>>>
>>>
>>> On Wed, Jun 29, 2011 at 11:17 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>>
>>>> Here's the blueprint declaration:
>>>>
>>>> admin_base = Blueprint('admin_base', __name__,
>>>> template_folder='templates')
>>>>
>>>> Here's the view function:
>>>>
>>>> @admin_base.route('/')
>>>> @login_required
>>>> def index():
>>>> user = None
>>>> if 'logged_in_user' in session:
>>>> user = Admin.find_by_email(session['logged_in_user'])
>>>> return render_template('admin_base/index.html', user=user)
>>>>
>>>> and here's the error:
>>>>
>>>> ...
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/app.py",
>>>> line 1041, in dispatch_request
>>>> return self.view_functions[rule.endpoint](**req.view_args)
>>>> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line
>>>> 19, in decorated_function
>>>> return f(*args, **kwargs)
>>>> File "/Users/charlieevett/code/jiffy-web/jiffy/admin/login.py", line
>>>> 30, in index
>>>> return render_template('admin_base/index.html', user=user)
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
>>>> line 122, in render_template
>>>> return _render(ctx.app.jinja_env.get_template(template_name),
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
>>>> line 716, in get_template
>>>> return self._load_template(name, self.make_globals(globals))
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/environment.py",
>>>> line 690, in _load_template
>>>> template = self.loader.load(self, name, globals)
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/jinja2/loaders.py",
>>>> line 115, in load
>>>> source, filename, uptodate = self.get_source(environment, name)
>>>> File
>>>>
"/Users/charlieevett/code/jiffy-web/virtualenv/lib/python2.6/site-packages/flask/templating.py",
>>>> line 61, in get_source
>>>> raise TemplateNotFound(template)
>>>> TemplateNotFound: admin_base/index.html
>>>>
>>>>
>>>> On Wed, Jun 29, 2011 at 10:46 AM, Adam Patterson <fakeempire@gmail.com>wrote:
>>>>
>>>>> I have the same setup as you and I'm not having any issues. I did not
>>>>> have to remove the module/blueprint name.
>>>>>
>>>>> Could you provide more information, like what error you're actually
>>>>> getting?
>>>>>
>>>>>
>>>>> On Wed, Jun 29, 2011 at 9:32 AM, Charlie Evett <charlieevett@litl.com>wrote:
>>>>>
>>>>>> I'm in the middle of upgrading to 0.7. The upgrade script worked, but
>>>>>> one change is causing lots of issues is the change of template syntax.
>>>>>>
>>>>>> I had a lot of this kind of thing all over the place:
>>>>>>
>>>>>> return render_template('admin_base/index.html', user=user)
>>>>>>
>>>>>> where 'admin_base' is the old name of the module but is now the name
>>>>>> of the Blueprint declared as:
>>>>>>
>>>>>> admin_base = Blueprint('admin_base', __name__)
>>>>>>
>>>>>> also everywhere I have inherited templates declared it is failing:
>>>>>>
>>>>>> {% extends "admin_base/base.html" %}
>>>>>>
>>>>>> looks like I have to remove the module names everywhere. Is that the
>>>>>> easiest way?
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>