templatetags

Django templatetag scope forcing me to do extra queries

你说的曾经没有我的故事 提交于 2019-12-07 06:52:06
问题 The problem is that if I call a templatetag into a block and it fills me a variiable with the usual context[varname]=something, then if I need that variable into another block, I have to call the templatetag again. This for me means extra db queries, which is really something I'm trying to avoid. This templatetag is called in a base template which is extended by many other templates, so I can't just change all the views to pass something to the context, it makes no sense (WET principle?) Even

Handling request in django inclusion template tag

一个人想着一个人 提交于 2019-12-07 03:48:10
问题 I am new to Django and am trying to put an upload file form into an inclusion tag. So I can use it in various templates. I have created the following inclusion tag: #upload_files.py @register.inclusion_tag('upload_form.html') def upload_handler(context): request = context['request'] view_url = reverse('upload.views.upload_handler') if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect(view_url) upload_url,

Django templatetag for rendering a subset of html

梦想的初衷 提交于 2019-12-06 10:09:47
问题 I have some html (in this case created via TinyMCE) that I would like to add to a page. However, for security reason, I don't want to just print everything the user has entered. Does anyone know of a templatetag (a filter, preferably) that will allow only a safe subset of html to be rendered? I realize that markdown and others do this. However, they also add additional markup syntax which could be confusing for my users, since they are using a rich text editor that doesn't know about markdown

Django templatetag scope forcing me to do extra queries

帅比萌擦擦* 提交于 2019-12-05 09:24:50
The problem is that if I call a templatetag into a block and it fills me a variiable with the usual context[varname]=something, then if I need that variable into another block, I have to call the templatetag again. This for me means extra db queries, which is really something I'm trying to avoid. This templatetag is called in a base template which is extended by many other templates, so I can't just change all the views to pass something to the context, it makes no sense (WET principle?) Even a context processor would be not good because I don't want to call it for every page rendered in the

Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:

送分小仙女□ 提交于 2019-12-03 18:55:26
问题 I want a menu thats custom depending which group you are member of. Im using Django 1.10.1, allauth and so on. When im trying to make my templatetag it fails and it says:¨ TemplateSyntaxError at / 'my_templatetag' is not a registered tag library. Must be one of: account account_tags admin_list admin_modify admin_static admin_urls cache i18n l10n log socialaccount socialaccount_tags static staticfiles tz 'my_templatetag.py' looks like this: from django import template from django.contrib.auth

Django template tags with same name

好久不见. 提交于 2019-12-01 06:17:12
For example I have 2 templatetags app1 templatetags app1_tags.py def custom_tag() app2 templatetags app2_tags.py def custom_tag() If I load in template both templatetags {% load app1_tags %} {% load app2_tags %} I have two tags with the name custom_tag . How can I use them in my template? Must I rename them? I know this is not the best solution but depending on your needs it can be helpful. This only works if the apps are made by you or if you overwrite the template tags This option is to give different names to each tag: app1_tags.py @register.filter(name='custom1') def custom_tag(): # Your

Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:

邮差的信 提交于 2019-11-30 02:38:37
I want a menu thats custom depending which group you are member of. Im using Django 1.10.1, allauth and so on. When im trying to make my templatetag it fails and it says:¨ TemplateSyntaxError at / 'my_templatetag' is not a registered tag library. Must be one of: account account_tags admin_list admin_modify admin_static admin_urls cache i18n l10n log socialaccount socialaccount_tags static staticfiles tz 'my_templatetag.py' looks like this: from django import template from django.contrib.auth.models import Group register = template.Library() @register.filter(name='has_group') def has_group(user

Mako templates using Django template tags

无人久伴 提交于 2019-11-29 07:25:10
Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration , but its template tags use Django's templates. If we used Django templates we could just {% load facebook_tags %} {% facebook_button %} {% facebook_js %} How can I do the same thing in Mako? You can inline strait up python in Mako, but I haven't figured out how to do it that way either. Final Fix <%! from django.template import Template, Context %> <% tpl = "{% load facebook_tags %}{% facebook_button %}{% facebook_js %}" %> ${Template(tpl).render(Context(dict_=dict(request

Mako templates using Django template tags

半城伤御伤魂 提交于 2019-11-28 01:10:52
问题 Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration, but its template tags use Django's templates. If we used Django templates we could just {% load facebook_tags %} {% facebook_button %} {% facebook_js %} How can I do the same thing in Mako? You can inline strait up python in Mako, but I haven't figured out how to do it that way either. Final Fix <%! from django.template import Template, Context %> <% tpl = "{% load facebook