{{}}
- это не тег, это выражение для подстановки переменной. Видимо, в контексте нет переменной site
. Её можно передать из представления, написать свой context processor или использовать django.contrib.sites.middleware.CurrentSiteMiddleware. class Post(models.Model):
owner = models.OneToOneField(User, verbose_name='Владелец', related_name='post')
@login_required
dev personal_page(request):
if request.method == 'GET':
post = request.user.post
form = WorkForm() if post else PostCreateForm()
return render(request, 'personal_page.hmtl', {'form': form })
elif request.method == 'POST':
post = Post.objects.get_or_create(owner=request.user)
...
(ns su.gornostaev.rstatfr2csv
(:use [clojure.xml :only (parse)])
(:use [clojure.string :only [index-of join split]])
(:use [clojure.java.io])
(:import java.io.File))
(defn parse-cmd
[args]
(when-let [file-name (first args)]
file-name))
(defn parse-file
[file-name]
(if (nil? file-name) nil (parse (File. file-name))))
(defn format-datetime
[dt]
(let [[date time] (split dt #"\s")]
(str (join "." (reverse (split date #"\."))) " " (subs time 0 (index-of time \:)) ":00")))
(defn merge-counters
[counters]
(map
(fn [item]
(let [[k & v] item]
(assoc (reduce (fn [acc val] (merge-with + acc val)) (first v)) :dt k)))
(reduce
(fn [acc val]
(let [{:keys [dt in out]} val]
(update-in acc [dt] (fnil #(conj % {:in in :out out}) []))))
{} counters)))
(defn parse-counters
[sensor]
(map
(fn [counter]
{:dt (format-datetime (:datetime (:attrs counter)))
:in (read-string (:realin (:attrs counter)))
:out (read-string (:realout (:attrs counter)))})
sensor))
(defn parse-sensors
[shop]
(map
(fn [sensor]
{:name (:name (:attrs sensor)) :counters (merge-counters (parse-counters (:content sensor)))})
shop))
(defn parse-shops
[dom]
(map
(fn [shop]
{:name (:name (:attrs shop)) :sensors (seq (parse-sensors (:content shop)))})
dom))
(defn parse-doc
[doc]
(parse-shops
(->>
doc
:content
first
:content)))
(defn save-csv
[data]
(with-open [w (writer (file "output.csv"))]
(doseq [shop data]
(doseq [sensor (:sensors shop)]
(doseq [counter (:counters sensor)]
(.write w (str (join "\t" (concat [(:name shop) (:name sensor)] (vals (into (sorted-map) counter)))) "\n")))))))
(save-csv (parse-doc (parse-file (parse-cmd *command-line-args*))))
class BaseHandler(tornado.web.RequestHandler):
def get_template_namespace(self):
ns = super(BaseHandler, self).get_template_namespace()
ns.update({
'static_srv': 'static.domain.ru',
})
return ns
var xhr = new XMLHttpRequest();
xhr.open("POST", '/some-url', true)
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send("param_name=param_val");
def simple_ajax(request):
if request.method == 'POST':
print(request.POST.get('param_name'))