我正在创建重定向并将对象模型传递给参数,但这不起作用。以下是代码:
picking = http.request.env['stock.picking'].browse([2]) # get an object model
test = '/test/picking/' + slug(picking) # prepare url with slug
return http.local_redirect(test, {}) # redirect
以下是重定向的路线
@http.route('/test/picking/<model("stock.picking"):picking>', auth='user', methods=['GET', 'POST'], type='http')
def method_test(self, picking=None, **kw):
print picking
print "test"
但是这给了我404,找不到路线。
日志结果是:
2016-12-20 20:14:18,990 19094 INFO NEW werkzeug: 127.0.0.1 - - [20/Dec/2016 20:14:18] "GET /test/picking/pg-000002-2 HTTP/1.1" 404 -
答案 0 :(得分:0)
test = '/test/picking/{}'.format(slug(picking)) # prepare url with slug
您的路线正在聆听/test/....
,但您正在重定向到test/...
还要确保您的控制器向客户端发送响应。这样的事情。
return http.request.render('<your_addon>.<your_template_id>', data)
答案 1 :(得分:0)
我以前没用过slug但是我决定帮助你。 所以我读了一些源代码并制作了自己的slug()工作代码。
2016-12-22 10:10:06,333 11747 INFO dec_21_01 werkzeug: 127.0.0.1 - - [22/Dec/2016 10:10:06] "GET /crmlead/create HTTP/1.1" 302 -
> /home/user/Git/controllers/main.py(60)show_details_crm_lead()
-> pass
(Pdb) l
57 @http.route('/crmlead/detail/<model("crm.lead"):lead>', type='http', auth="public", website=True)
58 def show_details_crm_lead(self, lead, **kwargs):
59 import pdb; pdb.set_trace()
60 -> pass
61
62 @http.route('/web/signup', type='http', auth='public', website=True)
(Pdb) print lead
crm.lead(2,)
和pdb:
import FacebookLogin
import FBSDKLoginKit
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if(FBSDKAccessToken.current() != nil)
{
//print permissions, such as public_profile
print(FBSDKAccessToken.current().permissions)
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "id, name, email"])
let connection = FBSDKGraphRequestConnection()
connection.add(graphRequest, completionHandler: { (connection, result, error) -> Void in
let data = result as! [String : AnyObject]
self.lbluser.text = data["name"] as? String
let FBid = data["id"] as? String
self.lblEmail.text = data["email"] as? String
let url = NSURL(string: "https://graph.facebook.com/\(FBid!)/picture?type=large&return_ssl_resources=1")
self.imageView.image = UIImage(data: NSData(contentsOf: url! as URL)! as Data)
})
connection.start()
}
}
所以它就这么简单。
PS。我不知道你的代码不起作用的原因,但只是按照我的代码将帮助你。 也许你正在使用不同的slug我不知道,向我们展示你的进口