2

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...

Community
  • 1
  • 1
Lior
  • 109
  • 1
  • 11
  • 1
    It doesn't make sense to use an angular expression as a template tag argument. The template tag is processed on the server side before the response is sent to the client, where angular is running. – Alasdair Nov 17 '13 at 22:44

2 Answers2

2

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 }}?

McAbra
  • 2,382
  • 2
  • 21
  • 29
  • this is not the same username in my case... I used rest_api in angular to get query of conversations and then I used ng-repeat on angular_conversations and I want to display on the screen the user name of each angular_conversation... but from the query I have only their IDs, which are the foreign keys for the models with their usernames... so I want to use django in order to translate these parameters... – Lior Nov 17 '13 at 22:57
  • Hi McAbra, I wrote the full problem I tackled in http://stackoverflow.com/questions/20040750/how-to-include-in-queryset-details-fields-of-a-foreign-key-django-and-rest-api – Lior Nov 18 '13 at 05:33
1

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//
zdwolfe
  • 85
  • 1
  • 5
  • Hi, I did it, as written in http://stackoverflow.com/questions/8302928/angularjs-with-django-conflicting-template-tags The problem is not because they have same symbols... – Lior Nov 17 '13 at 23:00