Saturday, 15 March 2014

python - Are dict() and add_csrf() the same? -



python - Are dict() and add_csrf() the same? -

i have 2 similar functions , wondering if dict , add_csrf same?

do both homecoming value related variables in template?

def main(request): """main listing.""" forums = forum.objects.all() homecoming render_to_response("forum/list.html", dict(forums=forums, user=request.user)) def forum(request, pk): """listing of threads in forum.""" threads = thread.objects.filter(forum=pk).order_by("-created") threads = mk_paginator(request, threads, 20) homecoming render_to_response("forum/forum.html", add_csrf(request, threads=threads, pk=pk))

kind of.

dict() built-in python function (or perchance class - i'm not on python details) accepts named arguments, , returns python dictionary.

as render_to_response expects dictionary (or rather django context object, dictionary do) sec argument, can utilize dict() there. as utilize dictionary literal:

render_to_response("forum/list.html", {"forums":forums, "user":request.user})

i can't find reference add_csrf in django documentation, imagine it's helper function someone's written csrf-related stuff. (@crazyshezy notes adds csrf token context passed template.)

as result beingness passed sec argument render_to_response, must homecoming dictionary (or django context object) too.

python django

No comments:

Post a Comment