Korred
Korred

Reputation: 31

Python Bottle - Get variable from template

I have template-file (.tpl) which has some additional python code in it, that stores data into a variable. How can I access this variable when I send/handle a POST request from that template?

Can anyone give me a quick example?

In .tpl:

...
%dummy="TEST"
...

In main.py:

...
@post('/template/')
def method():
    ????
...

Edit: After a little brainstorming im not sure if thats even possible. The ,tpl is more or less a HTML page, which, as far as I know, cannot transfer stuff like variables,structures like lists etc. Can anyone please confirm?

Upvotes: 0

Views: 1788

Answers (1)

Gianni Di Noia
Gianni Di Noia

Reputation: 1578

You can pass the variable in the url

<form action="/template/?variable={{dummy}}>

and then in the handler:

dammy = request.query.variable

See the related docs

Upvotes: 0

Related Questions