Hi Marc, I'm using AppStruct, which is a python framework that I developed to interface with mod_wsgi. I really dislike some of the overhead and complexity introduced by MVC type frameworks for simple projects.
I've put together a pretty complete example of using AppStruct. This is designed to run with Python 3 and mod_wsgi on RHEL/Centos linux. https://gist.github.com/390a0ced8e64c070aea1 Here is the login page from the example gist http://tcm.jason.boss.gahooa.com/auth/user/login A couple of my objectives were: 1. simple --- one file should be enough to get a webpage added to the project 2. elegant --- minimal typing overhead 3. powerful --- expose all of the layers down to the bare protocol level 4. easy --- if you don't need it, keep it out of your way At my company, we write large and complex custom web applications. We needed a way to do it that would stay our of our way, but give us the power to do many things. Let me know if you would like to explore further. Thanks. -- The HTML example was just using Python triple-quotes (which can span lines) to make it easy. Also I was using a generator expression to stand in for a loop. It is way way better than something like this: *** awful way to generate HTML in python *** html = '<h1>do this</h1> for row in rows: html += '<div class="row">FirstName: ' html += HS(row.FirstName) html += '<br />' html += 'LastName: ' html += HS(row.LastName) html += '<br />' html += '</div> On Fri, Oct 5, 2012 at 5:21 PM, Marc ThinlineData <[email protected]>wrote: > Hey Jason, > > Thank you for the quick reply. > > For some reason I was assuming mod_wsgi was embedding Python in the "PSP" > way as well. > > But you lost me on your html code there. What did you just do? Did you > just after all implement Python syntax in HTML without any > template/framework? > > My other approach was to make use of Mako, but since that too is a > template I am yet to adhere to the template terminology :( > > I have a Mako thread running here, but they are quite inactive in that > group. https://groups.google.com/forum/#!topic/mako-discuss/kiC6zAN0VmY > > To say the least, I am struggling to find a simple, light and "up-to-date" > method in allowing Python to work directly inside HTML, thus why you > surprised me there, please do share :) > > > On Friday, October 5, 2012 10:01:33 PM UTC+1, Jason Garber wrote: > >> Hi Marc, >> >> I think you are not understanding what mod_wsgi is. >> >> *"The aim of mod_wsgi is to implement a simple to use >> Apache<http://httpd.apache.org/> module >> which can host any Python <http://www.python.org/> application which >> supports the Python WSGI <http://www.wsgi.org/>interface. The module >> would be suitable for use in hosting high performance production web sites, >> as well as your average self managed personal sites running on web hosting >> services."* >> >> WSGI is the "Web Server Gateway Interface", as (mostly) defined in >> http://www.python.org/dev/**peps/pep-0333/<http://www.python.org/dev/peps/pep-0333/> >> >> mod_wsgi provides a mechanism to connect apache with python, so that >> python can form a response to a web request. However, the interface is >> very basic. Python is expected to return the (usually html) data directly. >> >> Any templating type systems would happen at a level above mod_wsgi. Take >> a look at some of the python web frameworks out there (bottle, flask, >> django, etc...) to see what they have to offer. >> >> Under mod_python, the PSP handler is what was responsible for the syntax >> you were referencing. In the same way, if such a thing exists to be run >> under WSGI, it would be a separate project (and be able to run on any >> compliant wsgi server). >> >> I am not personally aware of such a thing. Personally, I accomplish a >> similar feat using python code directly: Given that HS() is a function >> which encodes HTML entities, and QA() is an xmlish quote attribute >> function, and UE() is a url encode function: >> >> html = ''' >> <div> >> <h1>Hi, this is an example</h1> >> <h2>Record List</h2> >> * ''' + ''.join('''* >> <div class="record"> >> First Name: ''' + HS(row.FirstName) + '''<br /> >> Last Name: ''' + HS(row.LastName) + '''<br /> >> <a href=''' + QA('/user/details?id=' + UE(row.ID)) + '''>Details</a> >> </div> >> * ''' for row in GetList()) + '''* >> </div> >> ''' >> >> I've used PHP and ASP.Net razr, and this isn't that much different. It >> requires you to think a little harder sometimes, but it is very possible to >> get the same effect using python syntax directly embedded in a view >> function. >> >> JG >> >> >> >> >> >> On Fri, Oct 5, 2012 at 4:50 PM, Marc ThinlineData <[email protected] >> > wrote: >> >>> I was wondering if mod_wsgi eventually allows me to embed Python code >>> directly into HTML such as mod_python does? >>> >>> I have installed mod_wsgi but I came short to finding any topic that >>> pointed me into a direction for allowing me to directly embedding Python >>> code into an HTML file. >>> >>> What I cant really figure out would be what the extension of the files >>> would then have to be ( .psp? ) >>> >>> And additionally to that, what is the coding syntax going to look like ( >>> {% %} ) ? >>> >>> I was looking at Mako for Python to embed Python code directly into >>> HTML, but it seems Mako still uses the template approach. And I am not >>> really to happy about the entire MVC terminology for the small fixes and >>> patches I need to do on certain websites. >>> >>> Hope someone can direct me to an article or tutorial that covers >>> mod_wsgi with Python embedded into HTML. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "modwsgi" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/modwsgi/-/g6BQdctrAj8J<https://groups.google.com/d/msg/modwsgi/-/g6BQdctrAj8J> >>> . >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to modwsgi+u...@** >>> googlegroups.com. >>> >>> For more options, visit this group at http://groups.google.com/** >>> group/modwsgi?hl=en <http://groups.google.com/group/modwsgi?hl=en>. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/modwsgi/-/xZHEzegEbl8J. > > 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/modwsgi?hl=en. > -- You received this message because you are subscribed to the Google Groups "modwsgi" 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/modwsgi?hl=en.
