I have questions for experienced developers:
I am trying to create new custom web controller route. But I do find some troubles here. Let me put down the example. Image this situation:
custom controller:
@http.route(['/<path:custom_path>/'], type='http', auth='public', website=True)
def render_new_template(self, **post):
is conflicting with basic controller:
@http.route('/', type='http', auth="public", website=True, sitemap=True)
def index(self, **kw):
The effect of above code is:
- when I request website.com/custom_path/ URL - it works perfectly and renders my custom template
- when I request a core page website.com/page URL - it starts to render it with my new custom template, which is not the effect I want
How to deal with routing in such situation? I do really want to have the same short URLs without additional path like following:
/additional_path/<path:custom_path>/
or even short one:
/c/<path:custom_path>/
I did some research as odoo web controller routing is based on werkzeug, so I found some recommendations but neither was precise enough for Odoo.
The following solutions were mentioned:
- do it with custom converter
- do it with Importing werkzeug.routing, creating own map implementation, changing werkzeug.routing.Map to own implementation
- use "url_for" (probably only in case of Flask) which allows you to point to the
app.py:
app.route('/<path:pattern1>')
app.route('/<path:pattern1>/<path:pattern2>')
def catch_all(pattern1, pattern2=None):
return render_template('template.html', p1=pattern1, p2=pattern2)
app.route('/test')
def test_routing:
args = {'pattern1': 'Posts', 'pattern2': 'create'}
return render_template('test.html', args=args)
test.html:
<a href="{{url_for('catch_all', **args)}}">click here</a>
I know there is a url_for functionality in odoo but it is not doing exactly the same - it is pointing to the path not to the method of this route
I will be really grateful for help, and donate any guy that will help, explain and suggest kind of wise and pretty solution for my case.