In configuration file:
config.add_route('lang', '/lang-{code}')
In views:
@view_config(route_name='lang')
def lang(request):
code = request.matchdict['code']
response = Response()
response.set_cookie('lang', value=code, max_age=31536000) # max_age = year
return HTTPFound(location=request.environ['HTTP_REFERER'])
The mechanism is simple: there is a dropped down menu item with languages and clicking on anyone must refresh site with new locale.
Runs without errors, but no cookie set up... What I did wrong?
Thanks!
HTTPFound takes a headers parameter. Try something like return HTTPFound(location='foo', headers=response.headers)