Discussion:
[bottlepy] get _url for mounted apps
Andy Salnikov
2015-07-02 22:11:33 UTC
Permalink
Hi,

I have split my large bottle app into few smaller apps which are all
mounted under root app. Now in one of the apps I want to generate URL for
the resource served by other app and that does not see m to work:

# actual applications live in separate files, here for simplicity it's all
together

app1 = Bottle()
app2 = Bottle()
app = Bottle()

app.mount('/app1', app1)
app.mount('/app2', app2)


@app1.route('/nice_plot/<name>', name='nice_plot')
def nice_plot(name):
return SomeData()

@app2.route('/plot_grid')
def plot_grid():
# and here I want to generate URL served by app1, e.g.
'/app1/nice_plot/123'

# tried this:
url = app1.get_url('nice_plot', name='123')

# but it returns '/app2/nice_plot/123' instead

Looking at how get_url() is implemented it's clear why it happens (it uses
SCRIPT_NAME to get URL prefix). Still I need to somehow make correct URL.

Is there a reasonably simple way to do what I want or should I abandon my
idea and hardcode URLs?

Thanks,
Andy
--
--
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 received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tristan Kohl
2015-07-03 07:43:09 UTC
Permalink
I don't know if I get you right, but I made myself a prototype class all
apps inherit from:

#!/usr/bin/env python3


from .bottle import Bottle


class Prototype(Bottle):
"""
Provide routing functionality for all Bottle Apps.
This is not a Standalone-App but some prototype.
"""

def __init__(self, parent, path, routelist):
"""
Initialise App.
"""
super().__init__()
self.parent = parent
self.path = path
self._routes(routelist)


def _routes(self, routelist):
"""
Routine to establish routes for requests according to routelist.
"""
for _route in routelist:
if len(_route) == 3:
_method = _route[2]
else:
_method = "GET"
self.route(
path = _route[0], callback = _route[1], method = _method
)

New apps will be generated like this:
#!/usr/bin/env python3


from .prototype import Prototype


class MainApp(Prototype):

def __init__(self, port = 12001):
routelist = (
( "/", self.index ),
( "/add", self.get_new ),
( "/add", self.add_new, "PUT" ),
( "/all", self.index_all ),
( "/data/<id>", self.save, "POST" ),
( "/search", self.search ),
( "/stylesheet/<sheet>", self.send_stylesheet ),
)
super().__init__(
parent = None,
path = "/",
routelist = routelist
)

Host and port are obviously only for the "root" app but every by this
approach every class got its own path attribute and is aware of its root
app.

I hope this helps you in your approach :)


Cheers,
Tristan
--
--
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 received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andy Salnikov
2015-07-03 22:37:10 UTC
Permalink
Hi Tristan,

I don't think this is relevant. The problem that I'm facing is that get_url
and multiple applications do not work together. I don't believe you
approach can solve that.

Cheers,
Andy
--
--
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 received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tristan Kohl
2015-07-04 01:23:01 UTC
Permalink
Hi Andy,

i figured you wanted some "subapps" but now I get you already solved this. I used my approach to solve this kind of problem by walking up the the "parent" attribute and use their "path" attribute to concat
--
--
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 received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...