Den tisdag 2 juni 2020 kl. 22:53:06 UTC+2 skrev Jan Gregorczyk:
>
> Hi! How to change my template tag?
> from django import template
>
> register = template.Library()
>
> @register.simple_tag
> def votes_up_exists(answer, user_id):
> pass
>
> how I use it - {% votes_up_exists answer
Sorry - I posted that without a link?
https://stackoverflow.com/questions/1333189/django-template-system-calling-a-function-inside-a-model
This is by design - and you should always try to simplify what you are
doing in django templates.
Regards,
Andréas
Den ons 3 juni 2020 kl 11:41 skrev
Hi Jan,
You can't do it like that. A templatetag is a simple function that is
handled in a special way by the django templating language.
See here for an explanation:
Med vänliga hälsningar,
Andréas
Den tis 2 juni 2020 kl 22:53 skrev Jan Gregorczyk :
> Hi! How to change my template tag?
>
Hi! How to change my template tag?
from django import template
register = template.Library()
@register.simple_tag
def votes_up_exists(answer, user_id):
pass
how I use it - {% votes_up_exists answer request.user.id %}
how I would like to use it - {% answer.votes_up_exists user_id %}
--
You
I meant to write "indeed this section of the same article seems to support
this -
https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#auto-escaping-considerations
"
On Sunday, November 24, 2019 at 6:43:44 PM UTC, Ross wrote:
>
> To create our own custom templ
To create our own custom template tags we have to define a Node subclass
which implements a render method.
Example from
https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#auto-escaping-considerations
import datetimefrom django import template
class CurrentTimeNode(template.Node
You might want to look at the code for making a tag like:
URLNode(Node)
line 408 of
https://github.com/django/django/blob/stable/1.6.x/django/template/defaulttags.py
Then extend that.
class MyAnchor(URLNode):
override the init function to accept the params your are sending and
override
Hi,
I am trying to create a custom template tag that generates a repetitive
HTML snippet. This tag is an anchor tag "a" with extra classes and styles,
plus some logic to apply additional classes and styles. I want the syntax
in the template to look something like:
{% my_anchor URL %}this is
On Tue, Aug 20, 2013 at 1:54 PM, Daniel Roseman wrote:
> Django doesn't care what app the tags are in, as long as that app is in
> INSTALLED_APPS and the tags are in the templatetags directory inside the app
> (and Python requires a blank __init__.py in that directory too).
On 2013-08-20, at 3:53 AM, kandelabr <kandel...@gmail.com> wrote:
> Hello!
>
> I want to define a new template tag and use it in a number of applications
> inside my django project. The documentation says:
>
> Custom template tags and filters must live inside a Djang
On Tuesday, 20 August 2013 11:53:27 UTC+1, kandelabr wrote:
> Hello!
>
> I want to define a new template tag and use it in a number of applications
> inside my django project. The documentation says:
>
> *Custom template tags and filters must live inside a Django app.
Hello!
I want to define a new template tag and use it in a number of applications
inside my django project. The documentation says:
*Custom template tags and filters must live inside a Django app. If they
relate to an existing app it makes sense to bundle them there; otherwise,
you should
I create custom django template and used Form (this tag has to be
universal):
This is file ratings.py use tags:
from django import template
from django.contrib.contenttypes.models import ContentType
from Ratings.forms import RatingsForm
register = template.Library()
class
Hi! But then the rendering wouldn't include the loaded templatetags.
And I guess it would be expensive to go through this process a couple times
for each call of the renderer.
On Monday, 30 April 2012 09:24:54 UTC-3, Daniel Roseman wrote:
>
>
>
> On Monday, 30 April 2012 09:03:56 UTC+1, 95felipe
On Monday, 30 April 2012 09:03:56 UTC+1, 95felipe wrote:
>
> Hi. I've been struggling with this problem the whole night and just
> couldn't find any solution. I've tried reverse engineering the
> template/base.py file, but things are getting ugly. :S
>
> How can I, inside a custom tag class
Hi. I've been struggling with this problem the whole night and just
couldn't find any solution. I've tried reverse engineering the
template/base.py file, but things are getting ugly. :S
How can I, inside a custom tag class (template.Node), make the parser
render a snippet of html with tags
On Sun, Oct 9, 2011 at 8:49 PM, Daniel Roseman wrote:
> On Sunday, 9 October 2011 20:26:26 UTC+1, Kayode Odeyemi wrote:
>
>> Hello,
>>
>> I'm creating a template tag that will will allow session variables stored
>> as strings or
>> dict in a view to be available in its
On Sunday, 9 October 2011 20:26:26 UTC+1, Kayode Odeyemi wrote:
>
> Hello,
>
> I'm creating a template tag that will will allow session variables stored
> as strings or
> dict in a view to be available in its template. The syntax is:
>
> {% session_value [view_name] [session_variable] [arg] %}
Hello,
I'm creating a template tag that will will allow session variables stored as
strings or
dict in a view to be available in its template. The syntax is:
{% session_value [view_name] [session_variable] [arg] %}
But at the moment I don't know how I can get Django to stop throwing name
errors
On 30 mar, 21:55, justin jools wrote:
> I've just started using custom tags and need some help parsing info
> to:
>
> @register.tag
> def friends_of(parser, token):
> tag_name, user_var = token.split_contents()
Don't assume you'll only have what you expected here.
I've just started using custom tags and need some help parsing info
to:
@register.tag
def friends_of(parser, token):
tag_name, user_var = token.split_contents()
return FriendsOfNode(user_var)
class FriendsOfNode(template.Node):
def __init__(self, user_var):
self.user_var =
I recently got a problem where I need to get field's value
automatically using templatetags.The idea follows which mentioned in
the book "Practical Django Project 2nd Edition", but the book version
is getting a list of objects where I want to get only a object's
value. I want to get the site
The first link I had seen and used. My custom query works, I had just
been having issues with the tags. I had been through the docs and seen
a different one on tags, but apparently passed over the one you posted
in the link. It filled in some of the gaps I was missing, thanks. Very
helpful.
--
To use custom SQL see this for reference:
http://docs.djangoproject.com/en/dev/topics/db/sql/
To create a templatetag see this for reference:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/
On Mon, Jun 14, 2010 at 10:08 PM, Cole743 <cole.rieger...@gmail.com> wrote:
&
Hello again,
My last question may have been unclear, so I'm going to be more
specific.
I want to use the results of this:
cursor.execute("SELECT * from sp_getreport(""varchar"" %s)", [usr])
(or something similar) In a custom template tag to display in a
template. The results of the query are:
a
Good to know. Thanks.
On Wed, Feb 17, 2010 at 3:44 AM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:
> On Feb 16, 10:57 pm, Joel Stransky wrote:
> > The problem is that if I load the tag inside base via {% load
> my_custom_tag
> > %} it breaks but if I
On Feb 16, 10:57 pm, Joel Stransky wrote:
> The problem is that if I load the tag inside base via {% load my_custom_tag
> %} it breaks but if I include that line inside mainContent, it works. My
> goal here was to load all custom tags in the base so that I'd never have to
Sorry, I meant custom filters, myModel.image|my_media_path
On Tue, Feb 16, 2010 at 4:57 PM, Joel Stransky wrote:
> I have a base.html template which includes a mainContent.html template.
> mainContent reads a relative image path from the model passed to it but has
> a
I have a base.html template which includes a mainContent.html template.
mainContent reads a relative image path from the model passed to it but has
a custom template tag used for locating the start of the path which makes it
easy to develop locally and deploy the project without having to change
On Sep 9, 4:00 pm, tdelam wrote:
> Hey,
>
> I would like to know if I should write a custom template tag or if
> anyone can give me some direction on how to do the following:
>
> 1) User visits a page on a web site, example.org/campaign/businessname
> 2) I capture
Hey,
I would like to know if I should write a custom template tag or if
anyone can give me some direction on how to do the following:
1) User visits a page on a web site, example.org/campaign/businessname
2) I capture "businessname" and fetch the details of that user from
the database and
Hi guys,
I got the solution for me.
Read here:
http://groups.google.com/group/django-users/browse_thread/thread/7b7dad85530eceed/63be3eb5e41ce9f0#63be3eb5e41ce9f0
regards
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Daymien has a similar issue at
http://groups.google.com/group/django-users/t/7b7dad85530eceed
Just wanted to link the two discussions.
On Jul 30, 12:11 pm, chefsmart wrote:
> There is absolutely no difference between my dev and production, only
> the database details
There is absolutely no difference between my dev and production, only
the database details in the settings.py are different.
The 'django.template.loaders.app_directories.load_template_source' is
not included in both my dev as well as my production setups (which is
in testing phase now).
So
And do you want to avoid
'django.template.loaders.app_directories.load_template_source' ?
It will work only when your template will not be found in default
template directory
So i guess there is no overhead when you use it in production.
May be you have DEBUG=True in your development version
I got no other custom tags. This is pretty confusing. It works
perfectly on the django dev server with no code changes.
Don't really know enough about the pre-requisites (settings.py, etc)
for using custom templatetags, so haven't progressed much in my
troubleshooting.
On Jul 29, 9:24 pm,
And what about other custom tags?
I actually have no more ideas, what it can be.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to
I get the following message. Please note that everything is ok in my
development setup, but the same thing doesn't work in my production
setup.
TemplateSyntaxError at /staff/
'smart_if' is not a valid tag library: Could not load template library
from django.templatetags.smart_if, No module
I my case custom tags are still working after i removed
''django.template.loaders.app_directories.load_template_source'' from
settings.
You can see comment in site-packages\django\template\loaders
\app_directories.py:
"""
Wrapper for loading templates from "templates" directories in
plates' ).
>
> On Jul 28, 11:23 pm, chefsmart <moran.cors...@gmail.com> wrote:
>
> > Is 'django.template.loaders.app_directories.load_template_source'
> > required in the TEMPLATE_LOADERS setting for custom template tags to
> > work?
--~--~-~--~~-
com> wrote:
> Is 'django.template.loaders.app_directories.load_template_source'
> required in the TEMPLATE_LOADERS setting for custom template tags to
> work?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Is 'django.template.loaders.app_directories.load_template_source'
required in the TEMPLATE_LOADERS setting for custom template tags to
work?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users&q
ctions to ease creation of
> custom template tags. So a natural doctest (or an example in the
> documentation) goes like this: define a compiler function and Node
> class with my helpers, register them with a tag library, define a
> bunch of template strings with these tags, then render
On Mon, Feb 16, 2009 at 11:49 AM, Daniel Roseman <
roseman.dan...@googlemail.com> wrote:
>
> On Feb 16, 4:23 pm, Ben Gerdemann wrote:
> > Is it possible to add a custom template tag to the admin without
> > modifying the Django source? I'd like to add a tag to display a
> >
On Feb 16, 4:23 pm, Ben Gerdemann wrote:
> Is it possible to add a custom template tag to the admin without
> modifying the Django source? I'd like to add a tag to display a
> different submit_line, but the only way I can figure out how to do
> this is by either adding one of
here's the code:
TEMPLATE
{% load more_news %}
{% get_morenews_list %}
{% for news in more_news %}
{{ news.title }}
{% endfor %}
MORE_NEWS.PY
from myproject.site.models import Blog
from django.template import Library,Node
register = Library()
def build_morenews_list(parser, token):
one more thing. the first one is working.
i tried to setup a second template tag for the page called
more_news.py. the first is working as recent_news.py.
recent_news.py gets the more recent entry, i have more_news.py set to
get 2-6. i have {% load more_news %} since the file is more_news.py,
thanks man, for some reason i couldn't get it and it was about to
drive me nuts :)
On Jul 3, 10:37 am, Berco Beute <[EMAIL PROTECTED]> wrote:
> It should be in:
> /project/application/templatetags/
>
> 2B
--~--~-~--~~~---~--~~
You received this message because
On Thu, 2008-07-03 at 07:33 -0700, [EMAIL PROTECTED] wrote:
> On my homepage I want to have a few different items, one is the recent
> news items. I created the recentnews.py file:
>
> from myproject.site.models import Blog
> from django.template import Library,Node
>
> register = Library()
>
Didn't mean to send it. In my template I'm using this to call the
recent news:
{% load recent_news %}
{% get_news_list %}
I'm getting a TemplateSyntaxError, 'recent_news' is not a valid tag
library: Could not load template library from
django.templatetags.recent_news, No module named
It should be in:
/project/application/templatetags/
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from
On my homepage I want to have a few different items, one is the recent
news items. I created the recentnews.py file:
from myproject.site.models import Blog
from django.template import Library,Node
register = Library()
def build_news_list(parser, token):
return NewsObject()
class
On Jan 24, 10:36 pm, hifire <[EMAIL PROTECTED]> wrote:
> Greetings group!
>
> I've been trying to get this code to
> work:http://www.djangosnippets.org/snippets/282/
>
> I created a templatetags folder in my app, and added __init__.py and
> usertags.py. I pasted the code from the snippets site
Greetings group!
I've been trying to get this code to work:
http://www.djangosnippets.org/snippets/282/
I created a templatetags folder in my app, and added __init__.py and
usertags.py. I pasted the code from the snippets site into my
usertags.py. I have a view define like this:
I was misunderstanding where the app_directories loader looks for
files. It makes sense now.
Thanks,
Steve
On Sep 30, 3:58 pm, AndrewK <[EMAIL PROTECTED]> wrote:
> You need to place your tag templates into the subdirectory called
> "templates" of your application directory.
> In that case
>
You need to place your tag templates into the subdirectory called
"templates" of your application directory.
In that case
django.template.loaders.app_directories.load_template_source would be
able to found your custom tag template. And you don't need to add this
directory's path to TEMPLATE_DIRS
I created a custom inclusion tag that makes use of a template file
named menu_tag.html. I placed that file in the app's subdirectory of
the template directory.
When I tried to make use of it I got a template does not exist
error.
I was able to resolve this by adding the app's subdirectory to
On Sep 6, 9:18 pm, RajeshD <[EMAIL PROTECTED]> wrote:
> On Sep 5, 12:03 pm, MichaelMartinides <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
>
> > Just to be sure.
>
> > If I have custom template tags within a TextAreafield of a model. I
> > would do
On Sep 5, 12:03 pm, MichaelMartinides <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> Just to be sure.
>
> If I have custom template tags within a TextAreafield of a model. I
> would do something like to following:
>
> def view(request, page):
> p = Page.object
Hi,
Just to be sure.
If I have custom template tags within a TextAreafield of a model. I
would do something like to following:
def view(request, page):
p = Page.objects.get(name=page)
t = Template( p.content )
content = t.render()
return render_to_response('page.html', {content:content
I'm using a custom templatetag, named "ifgreaterthan", as seen here:
http://nrcfosshelpline.in/code/browser/trunk/web/templatetags/base_utils.py
When template inheritance *isn't* used, any {% block xyz %} that
exists inside this tag shows correctly on the rendered page. However,
if the content
neebone <[EMAIL PROTECTED]> writes:
> Just to update, I'm getting the form to post to a different url which
> handles the logic of creating the comment then redirects back to the
> article page on success. All good. My only problem is what to do if
> the form contains missing fields - I need to
On Jul 6, 9:57 am, neebone <[EMAIL PROTECTED]> wrote:
> On Jul 6, 9:46 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > On Fri, 2007-07-06 at 08:26 +, neebone wrote:
>
> > [...]
>
> > > Ok, I've got a page which uses a generic view to load the article into
> > > the template.
On Jul 6, 9:46 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-07-06 at 08:26 +, neebone wrote:
>
> [...]
>
>
>
> > Ok, I've got a page which uses a generic view to load the article into
> > the template. All good so far. I've then created two template tags,
> >
On Fri, 2007-07-06 at 08:26 +, neebone wrote:
[...]
> Ok, I've got a page which uses a generic view to load the article into
> the template. All good so far. I've then created two template tags,
> list_comments and comment_form.
> list_comments is displayed first. The tag grabs the comments
>
On Jul 6, 9:13 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-07-06 at 08:04 +, neebone wrote:
> > Hi,
>
> > I'm trying to roll my own comments custom template tag and need to
> > action a browser redirect on successful comment posting. My problem is
> > that you can't
On Fri, 2007-07-06 at 08:04 +, neebone wrote:
> Hi,
>
> I'm trying to roll my own comments custom template tag and need to
> action a browser redirect on successful comment posting. My problem is
> that you can't just return HttpResponseRedirect and expect it to be
> executed. Is there an
Hi,
I'm trying to roll my own comments custom template tag and need to
action a browser redirect on successful comment posting. My problem is
that you can't just return HttpResponseRedirect and expect it to be
executed. Is there an "official" way to get the middleware to action
the redirect from
Hi all,
For sometime, I was thinking of a flexible yet easy to manage CMS for
creating wiki-like pages. That is:
- content and presentation of each page should be defined freely and
independently almost as free as in plain HTML documents when needed
- common blocks of content and templates
On 5/25/07, Bob Dively <[EMAIL PROTECTED]> wrote:
>
> On May 25, 4:06 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote:
>
> > That appears related to filters, somehow. Please include the full
> > code for your templates.
>
> Not really feasible since there are dozens.
Then try to simplify the
On May 25, 4:06 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote:
> That appears related to filters, somehow. Please include the full
> code for your templates.
Not really feasible since there are dozens.
--~--~-~--~~~---~--~~
You received this message because you
On 5/25/07, Bob Dively <[EMAIL PROTECTED]> wrote:
...
> Exception Type: TemplateSyntaxError
> Exception Value:Could not parse the remainder: custom_tags
> Exception Location: D:\python24\Lib\site-packages\django\template
> \__init__.py in __init__, line 558
>
> Still
Thanks for the info, Jeremy. If I change register.simple_tag("media")
to register.simple_tag(media), and I remove that extraneous path from
INSTALLED_APPS, I now get this error, also from template/__init.py__:
Exception Type: TemplateSyntaxError
Exception Value:Could not parse
On 5/25/07, Bob Dively <[EMAIL PROTECTED]> wrote:
This:
> register.simple_tag("media")
Should be this:
register.simple_tag(media)
And I doubt this is causing this problem, but this:
> 'myapp.main.templatetags',
shouldn't be in your INSTALLED_APPS.
'myapp.main' is the app; Django looks in
Despite several hours of poking around, I'm just not getting how to
make custom template tags and would greatly appreciate a little hand
holding.
I've created a directory called "templatetags" that's in the same
directory as models.py and views.py. In the templatetags director
ect and make it availabe to
the template for display without using a for loop or anything. for
example. project.name, project.slug, project.description, etc.
can anyone confirm for me that the custom template tags cannot return
an object? if that is the case, what do folks do to display data in
s
Here's one method of importing a common set of tags into your
app-specific templatetags modules. If there's an easier way, I'd
appreciate the advice.
1. Define your common tags, e.g. /yourproject/apps/templatetags.py:
from django import template
register = template.Library()
def
On Fri, 2006-08-04 at 21:50 -0700, bernie2004 wrote:
> when using a generic views object_list,
> i would like to know if there is a faster way to get all
> the extra variables inside a custom template tag:
>
> {% navigation pages page has_previous has_next %}
>
> and
>
> @register.simple_tag
>
when using a generic views object_list,
i would like to know if there is a faster way to get all
the extra variables inside a custom template tag:
{% navigation pages page has_previous has_next %}
and
@register.simple_tag
def navigation( pages, page, has_previous, has_next ):
... create
I'm going to bow my head in shame
I was SURE that I put it there! Thanks for making me look ivan!
Corey
On Jun 15, 2006, at 5:19 PM, [EMAIL PROTECTED] wrote:
>
> make sure your application exists in the project's settings file
> INSTALLED_APPS
>
>
> >
Don,Thanks for the reply. When I put in {% load reservations.reservationtags %} I get:'reservations.reservationtags' is not a valid tag library: Could not load template library from django.templatetags.reservationtags, No module named reservationtagsAny other ideas?Thanks,CoreyOn Jun 15, 2006, at
On Jun 15, 2006, at 2:05 PM, Corey wrote:
>
> Hi All!
>
> I've written a custom template tag, but I get the error:
> 'reservationtags' is not a valid tag library: Could not load template
> library from django.templatetags.reservationtags, No module named
> reservationtags
>
> I've looked in the
make sure your application exists in the project's settings file
INSTALLED_APPS
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to
Hi All!
I've written a custom template tag, but I get the error:
'reservationtags' is not a valid tag library: Could not load template
library from django.templatetags.reservationtags, No module named
reservationtags
I've looked in the archives and have tried everything I know so far:
1.
Hi all,
I've committed an rjwittams patch to trunk; among various
improvements, it slightly refactors the way custom template tags and
filters are registered. If you've written any custom template tags or
filters, they will no longer work until you make the changes outlined
here:
http
85 matches
Mail list logo