http://weever.berlios.de 会话默认使用twisted.web处理: $ b来自twisted.application导入服务的$ b,来自nevow导入appserver的 来自nevow import rend的,加载器,标签为t,inevow 类RootPage(rend.Page): addSlash = True def display_session(self,ctx,data): return inevow.ISession(ctx).uid docFactory = loaders.stan( t.body [display_session]] ) application = service.Application( ''Foobar'') site = appserver.NevowSite(RootPage()) server = strports.service(''8080'',site) server.setServiceParent(application) 将它保存在.py或.tac中并使用twistd -noy filename.tac / .py运行它 并打开 http:// localhost:8080 / 查看你的会话uid。 如果您想要进行身份验证: http://nevowexamples.adytum.us/ sources / guarded.py http:// nevowexamples .adytum.us / sources / guarded2.py 有两个例子(在标准的nevow发行版中)显示如何处理应用程序中的身份验证 透明的方式(你不要...... b $ b必须以任何方式触摸你的应用程序来添加用户身份验证, 这意味着你可以在不处理这方面的情况下编写所有内容 应用程序然后再添加它。) 要重定向到另一个URL,只需调用IRequest(ctx).redirect(newurl) $渲染开始前的b $ b(如在rend.Page.beforeRender中)或在 rend.Page.locateChild。 HTTPAuthentication易于处理: http://nevowexamples.adytum.us/sources/http_auth.py 只使用该类作为阻止页面的基类。 (此示例是标准nevow发行版的一部分)。 Nevow没有过滤器,因为它们是由twisted.web或 twisted.web2处理(希望很快,这将成为运行nevow所需的 网络服务器之一,其他是lighttpd,apache ,任何WSGI 应用服务器,nevow实际上是第一个支持 WSGI服务器的框架。 如果你想要使用你需要的另一种模板语言 写一个自定义加载器。过去有人这样做了(我不记得那个项目的 url)使用了类似猎豹的模板。 然后是最后一个点: 您可以使用 nevow.static.File公开目录或文件 暴露的对象是: 那些在rend.Page.children dict中设置的值,你可以用 到达它们的网址如下: http://www.example.com/url/that/retu..._children_dict 或者将一个对象分配给child_foobar属性,例如: p = rend.Page() p.child_foobar = static .File(''/ etc /'') 或者从child_foobar方法返回一个对象。 或覆盖rend.Page。 childFactory(self,ctx,segment)以动态方式返回一个 对象,具体取决于segment参数的值。 在我看来你真的没跟踪过Nevow,你的信息是非常不完整的。我想你应该在谈论 Nevow :)之前完成它。 - Valentino Volonghi又名Dialtone 现在运行MacOSX 10.4 博客: http:// vvolonghi .blogspot.com http://weever.berlios.deSessions are handled by default with twisted.web:from twisted.application import service, strportsfrom nevow import appserverfrom nevow import rend, loaders, tags as t, inevowclass RootPage(rend.Page):addSlash = Truedef display_session(self, ctx, data):return inevow.ISession(ctx).uiddocFactory = loaders.stan(t.html[t.head[t.title["Session example"]],t.body[display_session]])application = service.Application(''Foobar'')site = appserver.NevowSite(RootPage())server = strports.service(''8080'', site)server.setServiceParent(application)Save this in a .py or .tac and run it with twistd -noy filename.tac/.pyand open http://localhost:8080/ in your browser to see your session uid.If you want autentication: http://nevowexamples.adytum.us/sources/guarded.py http://nevowexamples.adytum.us/sources/guarded2.pyThere are 2 examples (in the standard nevow distribution) that show howto handle authentication in an application transparent way (you don''thave to touch your application by any means to add user authentication,which means you can write everything without taking care of this aspectof the app and then add it later).To redirect to another url just call IRequest(ctx).redirect(newurl)before the rendering begins (like in rend.Page.beforeRender) or inrend.Page.locateChild.HTTPAuthentication is easily handled: http://nevowexamples.adytum.us/sources/http_auth.pyjust use that class as a base class for your blocked page.(this example is part of the standard nevow distribution).Nevow doesn''t have filters because they are handled by twisted.web ortwisted.web2 (which is, hopefully soon, going to be one of the requiredwebservers to run nevow, the others are lighttpd, apache, any WSGIapplication server, nevow was in fact the first framework to supportWSGI servers).If you want to use a different templating language you just need towrite a custom loader. Somebody did this in the past (I don''t recall theurl of the project) that used cheetah-like templates.Then for the last point:you can expose directories or files usingnevow.static.Fileexposed objects are:those set as a value in rend.Page.children dict, you can reach them withan url like: http://www.example.com/url/that/retu..._children_dictOr assign an object to a child_foobar attribute like:p = rend.Page()p.child_foobar = static.File(''/etc/'')Or return an object from a child_foobar method.Or override rend.Page.childFactory(self, ctx, segment) to return anobject in a dynamic way depending on the value of the segment argument.It seems to me that you really never tracked Nevow, your information isvery incomplete. I think you should complete it before talking aboutNevow :).--Valentino Volonghi aka DialtoneNow Running MacOSX 10.4Blog: http://vvolonghi.blogspot.com http://weever.berlios.de 这篇关于Web框架评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 12:59