Lior
Lior

Reputation: 109

how to use angular expression inside template's tag of django?

I wrote in tags.py the following tag:

@register.simple_tag
def getUserName(request, user_id):
    return foo(user_id)

In my html template I combined django symbol {{ }} together with angular symbol {[{ }]} (AngularJS with Django - Conflicting template tags). so I wrote there this expression:

{% getUserName request {[{ angular_conversation.user_id }]} %}

The problem is the django parser it before angularjs parses the internal expression. Please tell me how can I cause it works...

Upvotes: 2

Views: 1335

Answers (2)

zdwolfe
zdwolfe

Reputation: 85

Change your default Django template delimiters or Angular's interpolation delimiters (see $interpolateProvider).

Something like:

myApp.config(function($interpolateProvider) {
  $interpolateProvider.startSymbol('//');
  $interpolateProvider.endSymbol('//');
});

Would allow you to use '//' in your templates, which would avoid the conflict.

//myScopeObject.something//

Upvotes: 1

McAbra
McAbra

Reputation: 2524

You can't. You have to think about, a workaround. From Django 1.5 you have the {% verbatim %} tag that prevents anything in it from rendering (including {{}} signs).

{% getUserName request {[{ angular_conversation.user_id }]} %} for what you are using this for? Can't you do it like {{ request.user.username }}?

Upvotes: 2

Related Questions