AngularJS で処理したいタグの周りを verbatim ~ endverbatim タグで囲むことで Django が {{ }} を処理するのを防ぎます。
<body ng-app="TestApp"> <div ng-controller="TestController as tc"> {% verbatim %} <p>{{ tc.message }}</p> {% endverbatim %} </div>
プログラミング系のメモとか、ゲーム・漫画の感想とか。
<body ng-app="TestApp"> <div ng-controller="TestController as tc"> {% verbatim %} <p>{{ tc.message }}</p> {% endverbatim %} </div>
<input is="core-input" id="input_records" required type="text" min="1" pattern="/^[\s]*[0-9]+[\s]*(,[\s]*[0-9]+[\s]*)*$/">
<input type="date" required id="input_date" name="date" value="{{ date }}">
Polymer({ date: new Date().toISOString().substr(0, 10), ...
Polymer({ date: new Date(), ready: function() { this.$.input_date.valueAsDate = this.date; }
<paper-input-decorator label="" error="入力必須" isInvalid="{{!$.input_name.validity.valid}}"> <input is="core-input" id="input_name" required type="text" value="{{ name }}"> </paper-input-decorator> <paper-button on-click="{{ post_data }}"></paper-button> <core-ajax id="post" url="/someurl" method="post" handleAs="json" on-core-response="{{ response }}" on-core-error="{{ error }}"> </core-ajax>
post_data: function() { if(!this.$.input_name.validity.valid){ alert("名前を入力してください"); } else { var data = { 'name': this.name, }; this.$.post.body = "data=" + JSON.stringify(data); this.$.post.go(); } }, response: function (event, response) { }, error: function(event, response) { }
class ActivityInfoListApi(View): def post(self, request, *args, **kwargs): data = request.POST.get("data", None) if data is None or len(data) == 0: return HttpResponseBadRequest() obj = json.loads(data) try: name = obj["name"] # 型チェック if (not isinstance(name, str) and not isinstance(name, unicode)): return HttpResponseBadRequest() # 受け取った値で何か処理… return HttpResponse("json形式文字列…") except KeyError: logging.error("Missing Parameter") return HttpResponseBadRequest()