templatetags

Custom template not loading correctly in Django

白昼怎懂夜的黑 提交于 2021-01-27 13:41:38
问题 I'm attempting to sub out the submit_line.html of the DetailView of an admin template in Django, but I'm getting this error: InvalidTemplateLibrary at / Module data_operations.templatetags.data_operations_tags does not have a variable named 'register' My settings.py contains my app name: INSTALLED_APPS = [ ... 'data_operations', ... ] And template data: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ # os.path.join(PROJ_DIR, 'templates') ], 'APP_DIRS':

How can I get a Django Template to render itself within a Mako Template?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 05:30:11
问题 We made the decision quite awhile ago to use Mako Templates in our Django project. We're also supporting Django Templates, since a lot of reusable apps (obviously) assume that Django Templating is available. I've found it possible to render Django Templates from Mako, but I haven't been able to find a way to make it work the other way around. I've just added django-articles to our list of apps, and it uses Django Templating. It assumes that the base.html file is an overriden Django Template.

Django template tags with same name

南楼画角 提交于 2019-12-30 09:54:14
问题 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? 回答1: 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

Django unable to find my custom template tags?

心不动则不痛 提交于 2019-12-23 04:31:23
问题 I'm creating custom template tags for my django site. I've followed the django documentation for this and have created a templatetags directory in my main application. /project/apps/core/templatetags -/__init__.py -/core_extras.py Since I am not sure if this is causing the problem, I should note I have this in my settings.py sys.path.insert(0, join(PROJECT_ROOT, "apps")) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites',

Error importing external library within Django template tag library

徘徊边缘 提交于 2019-12-12 14:37:57
问题 So I'm attempting to write a Django reusable app that provides a method for displaying your Twitter feed on your page. I know well that it already exists 20 times. It's an academic exercise. :) Directory structure is pretty simple: myproject |__ __init__.py |__ manage.py |__ settings.py |__ myapp |__ __init__.py |__ admin.py |__ conf |__ __init__.py |__ appsettings.py |__ feedparser.py |__ models.py |__ templates |__ __init__.py |__ templatetags |__ __init__.py |__ twitterfeed.py |__ views.py

Create template tags from the current function

混江龙づ霸主 提交于 2019-12-12 04:27:34
问题 I have formally constructed the function in my models.py file : from datetime import datetime from django.template.defaultfilters import date as datefilter from django.utils import translation def date_customerprofile(language): now_ = datetime.today() if language == 'English': translation.activate('en') return datefilter(now_, 'l, F j, Y') else: translation.activate('fr') return datefilter(now_, 'l, j F Y') I know Django's template language is NOT Python, so we can't write {{ customer.date

Re-usable HTML code / widgets

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:13:35
问题 Sometimes I need to use the same html code in different templates, like: <div class="mylist"><span>item-1</span><span>item-2</span>...</div> or more complicated widgets. I'm new to Django so I want to learn what do you usually do in these kinds of situations? Do you create your own template tags or what? 回答1: It sounds like you're after an inclusion tag, http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags . An inclusion tag is a very simple type of template tag for

How Django's url template tag works?

梦想的初衷 提交于 2019-12-10 11:38:56
问题 How does {"% url 'news_id' %"} work? I do have a url pattern url(r'^((?:\w|-)+)/$', 'comments.views.home', name='news_id') but I still get NoReverseMatch . It says Reverse for 'news_id' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['((?:\w|-)+)/$'] views.py from django.shortcuts import render from comments.models import User from django.http import HttpResponseRedirect, HttpResponse from django.template import RequestContext, loader, Context from comments

Django - Did you forget to register or load this tag?

回眸只為那壹抹淺笑 提交于 2019-12-09 04:41:21
问题 I've created a custom tag that I want to use, but Django can't seem to find it. My templatetags directory is set up like this: pygmentize.py from pygments import highlight from pygments.lexers import get_lexer_by_name from django import template from pygments.formatters.other import NullFormatter register = template.Library() @register.tag(name='code') def do_code(parser,token): code = token.split_contents()[-1] nodelist = parser.parse(('endcode',)) parser.delete_first_token() return CodeNode

Django Paginated Comments .. is there any existing solutions?

◇◆丶佛笑我妖孽 提交于 2019-12-08 06:46:27
问题 is there any existing pagination solution for Django contrib.comments? What I need is just a simple paginated django comments, for the Basic Blog application (from the Django Basic Apps) I used, using a simple has_previous and has_next I have copied the django.contrib.comments and tried modify the code but with no success. The code is pretty hard to understand (django/contrib/comments/templatetags/comments.py) because it consists of Node and Parser here is my comments.html template I used for