watsonpy / watson-framework

A Python 3 web app framework.
BSD 3-Clause "New" or "Revised" License
104 stars 12 forks source link

how to open render api in controler jinja2 #13

Closed krystian566 closed 9 years ago

krystian566 commented 9 years ago
from watson import framework
from watson.framework import controllers, __version__
from jinja2 import Environment, PackageLoader

or by type watson.jinja2 or watson.framework.jinja2 import

http://jinja.pocoo.org/docs/dev/api/#basics

  1. Basic example i think is not so good solution?
  2. I try to do more flex and no reaped html code? to open myapp/vievs/menu.html. get info in what controller i am. render myapp/vievs/menu.html
  3. How to import, use api, and render by jinja2? in controller of watson-framework.
krystian566 commented 9 years ago

from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('portfolio','./views'))
template = env.get_template('new.html')
version = 'progress version v{0}'.format(__version__)
y = template.render(the = version)

My progress right now.

krystian566 commented 9 years ago

I think is not good place for this problem

simoncoulton commented 9 years ago

Hey Krystian,

I'm not entirely sure what you're trying to do here, but if you wanted to return a different template you would do something along the lines of the following:

from watson.framework import __version__

class MyClass(controllers.Action):
        @view(template='edit')  # change this to the template you want to render if you want something different than the defaults
        def create_action(self):
            return {'version': __version__}

Have you had a look at the "Your First Application" in the docs? http://watson-framework.readthedocs.org/en/latest/getting-started/your-first-application.html

krystian566 commented 9 years ago

Good day Simon. yes i get some issue when i change those code line. @view(template='edit') default @view(template='get') or @view(template='controler_name/get') i try to @view(template='menu') // 'views/menu.html' What to do. Copy part of html code from view and return in template by adding some variables. General save time to prove something :)

Thank.

krystian566 commented 9 years ago

I forget import views I get those message:

    'module' object is not callable