Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2033 (closed defect: fixed)

Opened 11 years ago

Last modified 10 years ago

tg2 not wsgi compliant with public/static content

Reported by: lszyba1 Owned by: mramm
Priority: highest Milestone: 2.0b1
Component: Quickstart Templates Version: trunk
Severity: critical Keywords: wsgi, static files, deployment, for_url, templates


Can turbogears2 add a patch to make sure below works.....

Thanks, Lucas

Do you know how can I set server.webpath in wsgi scipt?

You should not need to set server.webpath. A well behaved WSGI application would automatically derive the application mount point from the value of SCRIPT_NAME passed by the underly WSGI adapter to the WSGI application. If TG2/Pylons doesn't do this, then it is broken.

Thus, you should just need to say:

WSGIScriptAlias /subapp /some/path/subapp.wsgi

Alias /subapp/images /some/otherpath/subapp/static/images Alias /subapp/css /some/otherpath/subapp/static/css

WSGIScriptAlias / /some/path/rootapp.wsgi

Alias /images /some/otherpath/rootapp/static/images Alias /css /some/otherpath/rootapp/static/css

and it should work. If not, then as I said, TG2/Pylons is arguably doing the wrong thing, or way that URLs within pages for images and css are being constructed wrongly.

See old discussion.


I believe that maintenance happening on older TG1 derived versions may have added a patch for this to subversion. Whether it has been released in a TG1 version I am not sure.



SCRIPT_NAME_patch_for_static_files.diff Download (2.5 KB) - added by lszyba1 11 years ago.
Patch for static content link rendering
index_patch_url_for.diff Download (1.1 KB) - added by lszyba1 11 years ago.
patch for sidebar template
login_handler.diff Download (2.8 KB) - added by lszyba1 10 years ago.
login_handler, and about, sidebar

Change History

comment:1 Changed 11 years ago by Chris Arndt

  • Keywords needs feedback, wsgi, files, deployment added; wsgi public image css deploy removed

Can you please provide a test case that breaks where it shouldn't with an explanation?

Please don't just paste discussions from the mailing list here without providing context.

comment:2 Changed 11 years ago by lszyba1

The basic problem is that when you deploy tg app under mod_Wsgi I deploy apps not as root mounted app but under some name.

(root mounted) example.com/ vs (not root mounted) example.com/myapp/

The way you mount the non root app in apache configuration is this:

  1. (you create an alias to the wsgi script in your apache settings)
  2. the wsgi script that I'm aliasing has all the information it need to load tg2 app

(example) WSGIScriptAlias /myapp /some/path/myapp.wsgi Above should run my app example.com/myapp/ WSGIScriptAlias /myapp3 /some/path/myapp.wsgi Would run my app example.com/myapp3/

When this happens a "SCRIPT_NAME" variable is passed to tg2 app(this is a wsgi standard as I'm being told from wsgi list), in the example above the script name I believe is "/myapp/". What this does is tells pylons app that everything needs to be prefixed with "myapp" example.com/myapp/index or example.com/myapp/adduser. The problem with this is that all url inside the project are prefixed but the static files "images and css" are not prefixed.

So while my app knows the url is example.com/myapp/index the static files have no idea about the prefix and are pointing to example.com/images instead of pointing to example.com/myapp/images

Due to wsgi specifications( http://wsgi.org/wsgi/Specifications/routing_args) I should be able to change the name of the prefix(SCRIPT_NAME) anyway I want and all tg2 app and static content should be able to figure out the new url).

The only thing I should need to change is Alias variable. WSGIScriptAlias /myapp3 /some/path/myapp.wsgi would display example.com/myapp3/images WSGIScriptAlias /myapp4 /some/path/myapp.wsgi would display example.com/myapp4/images

I hope this clears things up. It seems to me that "script_name" is already implemented withing tg2 but its not implemented for static content.

comment:3 Changed 11 years ago by lszyba1

Install apache, mod_wsgi create apache file and enable the site. You do it by: WSGIScriptAlias /myapp /some/path/myapp.wsgi

the myapp.wsgi script holds settings for production.ini and base dir folders. I can paste the actual files later if you want.

restart apache and I am able to access my site using this url and all its functions

localhost/myapp localhost/myapp/adduser localhost/myapp/deleteuser

except for localhost/myapp/images localhost/myapp/css localhost/myapp/javasctipt (maybe, didn't test it)

These SCript_name variable should work for all url links. Let me know and I can supply you with the whole brand new quickstarted app with all wsgi settings set.

Thanks, Lucas

comment:4 Changed 11 years ago by lszyba1

Hello, FIX: the default templates will need to change In lib/helpers.py the following will need to be imported: from routes import url_for

In master.html a css stylesheet will need to be changed to: <link rel="stylesheet" type="text/css" media="screen" href="${h.url_for('/css/style.css')}" />


<img src="${h.url_for('/images/under_the_hood_blue.png')}" alt="TurboGears" />

header.html <img src="${h.url_for('/images/logo.png')}" alt="TG2!"/>

possibly login.html

comment:5 Changed 11 years ago by lszyba1

  • Keywords deployment, for_url, templates added; needs feedback, deployment removed

Attaching a patch that fixed this bug. Please patch the current version.

Thanks, Lucas

Changed 11 years ago by lszyba1

Patch for static content link rendering

comment:6 Changed 11 years ago by lszyba1

  • Owner changed from faide to Chris Arndt
  • Component changed from TurboGears to Quickstart Templates

comment:7 Changed 11 years ago by Chris Arndt

  • Owner changed from Chris Arndt to mramm

Changed 11 years ago by lszyba1

patch for sidebar template

comment:8 Changed 11 years ago by lszyba1

One thing I forgot is that in a login.html there is a login_handler which I think needs to be tg.url() ed. PLease check, I wasn't sure what its doing so I didn't change it in a patch.


comment:9 Changed 10 years ago by mramm

  • Status changed from new to assigned
  • Milestone changed from 1.9.7b1 to 2.0b1

This is mostly fixed, but we need to test this to make sure that it's working properly, and that all static resources use tg.url()

comment:10 follow-up: ↓ 11 Changed 10 years ago by lszyba1

It is tested and working on the non-identity part. I have not tested it with identity and login logoff buttons.

comment:11 in reply to: ↑ 10 Changed 10 years ago by mramm

  • Status changed from assigned to closed
  • Resolution set to fixed

It is tested and working on the non-identity part. I have not tested it with identity and login logoff buttons.

Ok, marking this one as fixed.

Please open a new ticket if turning on authorization breaks anything.

comment:12 Changed 10 years ago by lszyba1

  • Status changed from closed to reopened
  • Resolution fixed deleted

The new template in tg.devtools is missing few tg.url.

I'm attaching a patch to fixes it in templates but after a user logs in the page gets redirected to '/' instead of tg.url('/'). I cannot find where in the code the process gets redirected.

Thanks, Lucas

Changed 10 years ago by lszyba1

login_handler, and about, sidebar

comment:13 Changed 10 years ago by faide

  • Status changed from reopened to closed
  • Resolution set to fixed

don't reopen old tickets like this. Open a new one.

Note: See TracTickets for help on using tickets.