for some reason, templatetags do not render in templates for django admin.
with this snippet from:
http://docs.djangoproject.com/en/dev/ref/templates/api/?from=olddocs#shortcut-for-simple-tags
{% if is_logged_in %}Thanks for logging in!{% else %}Please log in.{% endif %}
when placed in admin index.html, if a user is logged in, it sho...
I have two templatetags in my app which contain forms which show entries in db. When I alter data or add new entry to db, the forms show the old data. While in admin panel everything is correct (updated). When I restart the server (I mean manage.py runserver) forms show updated db entries. How to make the forms show updated data?
regard...
If I have created a template tag:
@register.simple_tag
def last_books(a_cat, cutoff=5):
objects = Books.objects.filter(category=a_cat)
return objects[:cutoff]
How can I do something like this in my template:
{% for book in last_books 'Sports' 3 %}
I am currently getting this error:
'for' statements should use the format...
If I start python from the command line and type:
import random
print "Random: " + str(random.random())
It prints me a random number (Expected, excellent).
If I include the above-two lines in my django application's models.py and start my django app with runserver I get the output on the command line showing me a random number (Grea...
Hi, 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...
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
|__ adm...
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....
I have a template filter that performs a very simple task and works well, but I would like to use a decorator on it. Unfortunately the decorator causes a nasty django error that doesn't make any sense...
Code that works:
@register.filter(name="has_network")
def has_network(profile, network):
hasnetworkfunc = getattr(profile, "has_%...
I need to do something like
{{ article.product.images.first.image.url }}
In my template, but there is no "first" (images is a RelatedManager for which I found very little documentation).
Is there another way to do this? I can get the first model with
{{ article.product.images.get_query_set|first }}
But then I need to dig a few pro...
Hello,
I am writing a python website built on the back of the django framework, I am looking for a way to highlight the current link the user is on depening on what the URL, I thought doing some thing like this would work.
What I have done is create a new application called nav and built some templatetags, like so,
from django impor...
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 tem...
Is it possible to load a django template tag/filter to use as a function in one of my template tags?
I'm trying to load up some of the django.contrib.humanize filters so I can apply them to the results of some of my custom template tags. I can't seem to import them at all, and I don't want to have to rewrite any of that code.
...
I am applying the 'url' template tag to all links in my current Django project.
I have my urls named like so...
url(r'^login/$', 'login', name='site_login'),
This allows me to access /login at my site's root. I have my template tag defined like so...
<a href="{% url site_login %}">
It works fine, except that Django automatically ...
I would like to write a Django template tag to which I can pass a variable.
I would like the template tag to behave differently depending on what type of model field the variable was derived from (CharField, BooleanField, IntegerField, etc.) as well as other information used in the field's definition (max_length, etc.)
I can pass the v...
I'm using a ModelForm class to generate a bunch of checkboxes for a ManyToManyField but I've run into one problem: while the default behaviour automatically checks the appropriate boxes (when I'm editing an object), I can't figure out how to get that information in my own custom templatetag.
Here's what I've got in my model:
from mypro...
Is there a way to check if a template tag exists before using the template tag?
In other words, I would like to be able to do something like this:
{% load my_custom_tags %}
...
{% ifloaded my_custom_tags %}
{% some_custom_tag %}
{% endifloaded %}
...
Hi overflowers,
I am using django to create a web-application.
I have created a template in where I load a templatetag. In this templatetag i load another templatetag. From the template I pass context to the first templatetag, but the context is not available from the second templatetag (inside the first templatetag) - see below.
I ho...
Trying to solve a problem with templatetags.
I have two templatetags:
@register.inclusion_tag('directory/_alphabet.html')
def alphabet_list(names):
""" Return a list of letters that last names start with. """
return { 'letters': [name.last_name[0] for name in names] }
class NameNode(template.Node):
def __init__(self, lette...
My Django site has many templatetags directories, can I use Django templatetags on Google App Engine?
...
I tried to implement the solution proposed by T. Stone on my question "how-do-i-pass-a-lot-of-parameters-to-views-in-django" ([link text][1]).
I can't manage to get any result. It's difficult to find information about the compile_filter(), but as far as I understand cls(queryset=parser.compile_filter(tokens[2]), template=template) should...