Matthew Dreon | 1 Dec 22:48 2011

Static files in Bottle with Mako

I currently reference my static files this way:

 <at> app.get('/_static/<url:path>', name='static')
def serve_static(url):
    path = "%s\\_static\\" % (os.getcwd())
    return static_file(url, root=path)

I'd like to combine this with the get_url function so that I can
create relative paths throughout the structure of my site.  This
stackoverflow post describes much of what I'm doing:
http://stackoverflow.com/questions/6978603/how-to-load-a-javascript-or-css-file-into-a-bottlepy-template

However, I don't understand what the additional route does:
 <at> route('/')
 <at> view('index')
def index():
    return { 'get_url': get_url }

and I have not been able to get Mako to understand a call to Bottle.
I would imagine it would be something like this in the template code:
<% app.get_url('static', '/css/main.css') %>"  but that results in
AttributeError: 'Undefined' object has no attribute 'get_url'.

Any help would be appreciated.

Iuri | 1 Dec 23:32 2011
Picon

Re: Static files in Bottle with Mako

I don't use Mako, so maybe I'm wrong about it.


You can write python code in Mako template, so you can just do:

<% from bottle import url %>

After that, just call url('static',url='/css/main.css') in your template.

cheers,
iuri


On Thu, Dec 1, 2011 at 7:48 PM, Matthew Dreon <matthew <at> dreon.org> wrote:
I currently reference my static files this way:

<at> app.get('/_static/<url:path>', name='static')
def serve_static(url):
   path = "%s\\_static\\" % (os.getcwd())
   return static_file(url, root=path)

I'd like to combine this with the get_url function so that I can
create relative paths throughout the structure of my site.  This
stackoverflow post describes much of what I'm doing:
http://stackoverflow.com/questions/6978603/how-to-load-a-javascript-or-css-file-into-a-bottlepy-template

However, I don't understand what the additional route does:
<at> route('/')
<at> view('index')
def index():
   return { 'get_url': get_url }

and I have not been able to get Mako to understand a call to Bottle.
I would imagine it would be something like this in the template code:
<% app.get_url('static', '/css/main.css') %>"  but that results in
AttributeError: 'Undefined' object has no attribute 'get_url'.

Any help would be appreciated.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
Matthew Dreon | 2 Dec 04:54 2011

Re: Static files in Bottle with Mako

Thanks,

I was able to get it to work using the following:

<% from bottle import url %>

<% context.write(url(routename='static', url='css/main.css')) %>

One other note, I was using this notation and it failed to find the routename 'static'

app = Bottle()

<at> app.route(..... name="static")

I changed the code to just using the basic instance of <at> route and my Mako template was able to find the routename.

Matt





On Thu, Dec 1, 2011 at 4:32 PM, Iuri <iurisilvio <at> gmail.com> wrote:
I don't use Mako, so maybe I'm wrong about it.

You can write python code in Mako template, so you can just do:

<% from bottle import url %>

After that, just call url('static',url='/css/main.css') in your template.

cheers,
iuri


On Thu, Dec 1, 2011 at 7:48 PM, Matthew Dreon <matthew <at> dreon.org> wrote:
I currently reference my static files this way:

<at> app.get('/_static/<url:path>', name='static')
def serve_static(url):
   path = "%s\\_static\\" % (os.getcwd())
   return static_file(url, root=path)

I'd like to combine this with the get_url function so that I can
create relative paths throughout the structure of my site.  This
stackoverflow post describes much of what I'm doing:
http://stackoverflow.com/questions/6978603/how-to-load-a-javascript-or-css-file-into-a-bottlepy-template

However, I don't understand what the additional route does:
<at> route('/')
<at> view('index')
def index():
   return { 'get_url': get_url }

and I have not been able to get Mako to understand a call to Bottle.
I would imagine it would be something like this in the template code:
<% app.get_url('static', '/css/main.css') %>"  but that results in
AttributeError: 'Undefined' object has no attribute 'get_url'.

Any help would be appreciated.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
Marcel Hellkamp | 2 Dec 21:42 2011
Picon

Re: single source for both python 2 and python 3

Am 24.11.2011 01:49, schrieb Ralf Schmitt:
> Hi,
> 
> I've created a branch that provides a bottle.py that is usable both from
> python 2 and python 3 without running 2to3. It's available on github:
> 
>   https://github.com/schmir/bottle/commits/single-source
> 
> It's based on the 0.9 release branch and might be useful to some people.
> 
> It's probably too late to merge that in the 0.9 release branch, but
> would something like that be feasible for the upcoming release?
> 

Git master now runs natively with all supported versions of Python.
Thanks for your work and ideas! It was not that hard with the help of
your patches :)

Ralf Schmitt | 2 Dec 21:56 2011
Picon

Re: single source for both python 2 and python 3

Marcel Hellkamp <marc <at> gsites.de> writes:

> Git master now runs natively with all supported versions of Python.
> Thanks for your work and ideas! It was not that hard with the help of
> your patches :)

nice. do you still need help with the tests? I'd be willing to spent
some on them if there's still work to do. Will you backport the changes
to the 0.10  branch?

--

-- 
Cheers
Ralf

Marcel Hellkamp | 2 Dec 22:37 2011
Picon

Re: single source for both python 2 and python 3

Am 02.12.2011 21:56, schrieb Ralf Schmitt:
> Marcel Hellkamp <marc <at> gsites.de> writes:
> 
>> Git master now runs natively with all supported versions of Python.
>> Thanks for your work and ideas! It was not that hard with the help of
>> your patches :)
> 
> nice. do you still need help with the tests? I'd be willing to spent
> some on them if there's still work to do. Will you backport the changes
> to the 0.10  branch?

I did all the tests today. Everything runs just fine. Backporting is
possible, but a bit risky (to guarantee BC is hard). And it does not
really matter for users that use pip/easy_install anyway. I think I'll
just save that for 0.11

Ralf Schmitt | 2 Dec 22:53 2011
Picon

Re: single source for both python 2 and python 3

Marcel Hellkamp <marc <at> gsites.de> writes:

> I did all the tests today. Everything runs just fine. Backporting is
> possible, but a bit risky (to guarantee BC is hard). And it does not
> really matter for users that use pip/easy_install anyway. I think I'll
> just save that for 0.11

ok. I've added a tox.ini script in
https://github.com/defnull/bottle/pull/257. tox allows to easily test
the code with different python versions and different configurations.

The Mako and Jinja tests are currently failing (NameError: global name
'touni' is not defined). Try running "tox -e py27" to test it with
python 2.7.

--

-- 
Cheers
Ralf

Decaz | 3 Dec 12:13 2011
Picon

Debugging in IDE

How can I debug my application in IDE, for example, in PyCharm? In debug 
mode it steps through breakpoints only during server starting, but not 
running..

Iuri | 3 Dec 13:09 2011
Picon

Re: Debugging in IDE

Pycharm debugger calls a pydevd.py file to run the file in debug mode. Bottle starts another process without debug mode, so Pycharm can't handle it.

I'm not a heavy user of PyCharm, so I don't know how to solve it. Maybe you need to monkey patch bottle.run.

cheers,
iuri

On Sat, Dec 3, 2011 at 9:13 AM, Decaz <decaz89 <at> gmail.com> wrote:
How can I debug my application in IDE, for example, in PyCharm? In debug mode it steps through breakpoints only during server starting, but not running..

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
Marcel Hellkamp | 3 Dec 13:22 2011
Picon

Re: Debugging in IDE

Am 03.12.2011 12:13, schrieb Decaz:
> How can I debug my application in IDE, for example, in PyCharm? In debug 
> mode it steps through breakpoints only during server starting, but not 
> running..
> 

For starters, avoid multi-threaded servers (the default should work) and
do not enable auto-reloading.


Gmane