On Monday 12 October 2009 14:33:19 Diez B. Roggisch wrote:
> On Monday 12 October 2009 13:04:54 Daishy wrote:
> > Hi together,
> >
> > I got a problem using the tg.url function that i cant seem to fix: I
> > wrote a form which is basicly like the one in the tutorial (in the
> > documentationsection). It is defined outside the Controller and passed
> > to the template by one of the functions inside the controller. Now i
> > have the action attribute defined es url('/root/sub/save') which works
> > fine, if my app is hosted under '/'. Now i want to deploy it on
> > another machine, which uses apache+mod_wsgi and a subpath '/myapp'.
> > Within the templates and the controller url('/root/sub/method') gets
> > translated to '/myapp/root/sub/method' which is correct. The Form
> > however ist still /root/sub/save.
> > Am i not allowed to use the url-function outside of an controller and
> > what else should i do instead?
>
> Try making the action a callable. That should be evaluated and
> form-rendering-time, yielding the correct result.
>
> Like this:
>
> my_form = TableForm('my_form', action=lambda: url("/root/sub/method", ..)
>
That should not work on TW forms if they didn't change something recently. It
would print the repr of the lambda function.
As far as I have been able to understand the problem is caused by the fact
that you need at least one request to be able to setup correctly tw injected
urls.
I have been able to fix the problem by providing a fake request inside the
wsgi application initialization script with those few lines:
import paste.fixture
app = paste.fixture.TestApp(application)
app.get("/")
suppose you have something like
from paste.deploy import loadapp
application = loadapp('config:%s' % APP_CONFIG)
just add them after the application instance has been created.
This solved the problem when running the application, but keep in mind that
having urls called outside of controller methods will cause problems when
generating your application documentation by using sphinx. For this reason it
is usually better to create the form action urls inside the controller method
that will render the form and pass them to the form.display call inside the
template.
Probably another viable solution is to define a class for which its __str__
and __repr__ methods return a call to url, but that is a more fancy solution
:D
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---