Flask + AngularJS - Using url_for ()

I use AngularJS + Flask in my application, and I want to know how best to "create" the URL, and don't write any hard code for this. I have this situation:

* given that I use [[]] instead of {{}} for AngularJS.

<dd ng-repeat="item in myList">
    <span ng-click="doAction('{{ url_for('my_url', id="[[item.id]]") }}')">
      [[item.name]]
    </span>
</dd>

This will not work because Jinja2 executes the url_for () process before AngularJS, so "[[item.id]]" will not be replaced with AngularJS in time.

The problem is that I do not want to write in hard code like this:

<span ng-click="doAction('/my_url/[[item.id]]')">
    [[item.name]]
</span>

I'm new to AngularJS, maybe all my approaches are wrong, so does anyone know that the best way to get an element to click is to make a request with a URL based on the context of the clicked element

+4
2

. Jinja2 {% set ... %}.

, .

<dd ng-repeat="item in myList">
    {% set url = url_for('my_url', id="[[item.id]]") %}

    <span ng-click="doAction('{{ url }}')">
        [[item.name]]
    </span>
</dd>
+1

, URL-

(: Angular {[x]}:

<ul>
    <li ng-repeat="x in projects">
        {[x.title]}
        {% set url = url_for('static',filename="img/") %}

        <img src="{{url}}{[x.img]}">
    </li>
</ul>
+1

Source: https://habr.com/ru/post/1537761/


All Articles