Why is it ill advised to use pyramid.threadlocal.get_current_request?

My assumption is that the correct request object is not the guaranteed result, but I would like to know exactly why it's ill advised, and the recommended way is to pass the request object down the pipeline from a view function.

Answers


After the request object has gotten to the view it's recommended that you do not pass "as-is" to any non-web-specific code. Any code dealing with databases, etc shouldn't be coupled to pyramid's concept of a request. This pattern is easier to follow in Pyramid as it avoids a global request object.

The request object encompasses everything about why your view is being invoked, and making more code than necessary coupled to that object will cause you to write functions further down the pipeline that perhaps do "too much".


Need Your Help

JSON body always empty in Node.js application

javascript jquery ajax json node.js

I am building a simple application using Node.js. On the client, I am sending some JSON data using Ajax to the server with the following code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.