On Tuesday, 30 October 2018 20:12:11 UTC, Dave S wrote:
>
>
>
> On Tuesday, October 30, 2018 at 7:41:09 AM UTC-7, Francis Windram wrote:
>>
>> Good Evening,
>>
>> I'm a relative newby to web2py, but with a few years of Python under my 
>> belt and old knowledge of HTML (from the pre-HTML5 days).
>>
>> When I deploy a new release, part of the procedure is to update the 
>> version line in appconfig.ini, e.g.:
>>
>> [app] 
>> appname = Webapp
>> version = 1.0.0 
>>
>> to
>>
>> [app] 
>> appname = Webapp
>> version = 1.0.1 
>>
>>
>>
>> Now this all works fine, but I want to display this as part of the footer 
>> in a form akin to:
>>
>> Webapp v1.0.1, Copyright © 2018
>>
>> This footer is currently generated in (the default) layout.html as 
>> follows:
>>
>>     <footer class="footer">
>>       <div class="container-fluid">
>>         <div class="copyright pull-left">{{=T('Copyright')}} &#169; 
>> {{=request.now.year}}</div>
>>          <div id="poweredBy" class="pull-right">
>>             {{=T('Powered by')}}
>>             <a href="http://www.web2py.com/";>web2py</a>
>>           </div>
>>       </div>
>>     </footer>
>>
>>
>> I know that in a controller you can access the appconfig args using code 
>> along the lines of:
>>
>> from gluon.contrib.appconfig import AppConfig
>>
>> appconf = AppConfig(reload=False)
>> print(appconf.take("app.version"))
>>
>>
>> However, I have no idea how to do a similar call to the appconfig 
>> variables from a view.
>> Any ideas? Do I need a controller to serve this information to the view? 
>> And if so, in what controller file would that controller reside?
>>
>> Many thanks,
>> Francis
>>
>
> Views are assembled on the server (except for things like jQuery), and 
> have a "this piece is python" syntax which you can see in the footer 
> example  
> {{=T('Copyright')}} // Apply T() to the string 'Copyright' and insert here
> {{=request.now.year}}  // insert here the value of request.now.year
>
>
> See 
> <URL:http://web2py.com/books/default/chapter/29/05/the-views> 
>  ... the '{{ ... }}' construction is introduced right away.
>
> The part I find tricky here is that you need to do an import of AppConfig, 
> or I'd say just try adding this to your footer:
>
> {{ = appconf.take("app.version")}}
>
>
> I can do the import easily enough in the controller, so I've just tested 
> that.  Import AppConfig at the top of the module, and define appconf as 
> in models/db.py.  Then in your controller return statement add 
> ..., app_version = appconf.take("app.version"), ....
> and in your footer add 
> {{== app_version}}
> You can do this in whatever controller you want, and the view will then 
> display the version.
>
> Even better, since you probably want all pages to display the version, is 
> just set app_version in your model file (db.py is where I tested it), and 
> it then becomes a global.
>
> /dps
>
>  
Perfect! With the vars defined in db.py, this all works swimmingly! Thank 
you very much

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to