django-templates

How to save links with tags and parameters in TextField

I have this simple Post model: class Post(models.Model): title = models.CharField(_('title'), max_length=60, blank=True, null=True) body = models.TextField(_('body')) blog = models.ForeignKey(Blog, related_name="posts") user = models.ForeignKey(User) I want that when I insert in the form the links, then these lin...

How to make a "nested" translation string in Django template?

Here's a phrase I have to make translateable: Poll ends in 2 hours 23 minutes This string must have the main phrase and 'hour' and 'minute' in singular and plural forms. {% blocktrans %}Poll ends in {{ poll.expire_hours }} ??? {{ poll.expire_minutes }} ???{% endblocktrans %} What do I put then instead of ??? ? Solution: made a s...

How do you add and use just the Django version 1.2.1 template?

Thanks for the help. Currently I import in gae: from google.appengine.ext.webapp import template then use this to render: self.response.out.write(template.render('tPage1.htm', templateInfo )) I believe the template that Google supplied for Django templete is version 0.96. How do I setup and import the newer version of only the Django ...

how call a django tag from source

I have a custom tag in django, but i need use this functionality in a non-view, non-template stage without template engine, there is a way without repeat code? ...

Django template {% trans %} pluralization

According to this section in the Django docs I should use {% blocktrans %} for cases where I need to translate pluralizations. However, with an example like the following, isn't there something more convenient I can do? {% blocktrans count video.views.count as views %} The video has been viewed <span>{{ views }}</span> time {% plural %}...

Help with django filters

I am have a list of "Entries" I want to get the first entry in the list's "title". In the template I tried writing {{ Entries|first.title }} But it results in an error. Is there a way to achieve this without writing a loop or doing it in the view? ...

Porting Django's templates engine to C

Hi folks, I recently wrote a simple and tiny embedded HTTP server for my C++ app (QT) and I played a little bit with Ry's http-parser and loved it. This guy is crazy. So I told to myself: "Hey! Why not port the django template engine to C?" That'd be awesome! I know, it won't be an easy task (not at all, I know) but I'd really love to...

Django how to handle # in variable name.

I've got a dictionary in python which is assigned as a template variable. One of the keys is named "#text" but when i try to access it using {{ artist.image.3."#text"}} I get an error which is File "/home/jack/Desktop/test/appengine/lib/django/django/template/__init__.py", line 558, in __init__ raise TemplateSyntaxError, "Could n...

Django: common template subsections / simple html templatetags ?

What's a good way to handle commonly occurring subsections of templates? For example, there is a sub-header section that's used across 4 different pages. The pages are different enough to not work well with template inheritance (ie. "extends" doesn't fit well). Is "include" the recommended method here? It feels a bit heavyweight, requi...

Django: Is there any way to have "unique for date range"?

If my model for Items is: class Item(models.Model): name = models.CharField(max_length=500) startDate = models.DateField("Start Date", unique="true") endDate = models.DateField("End Date") Each Item needs to have a unique date range. for example, if i create an Item that has a date range of June 1st to June 8th, how ...

How retrieve first 6 element in the template

In my template I have this for loop: {% for member in blog.members.all %} {{ member.first_name }} {% endfor %} Is there a way to retrieve only the first 10 members and not all the members ? ...

How to loop X times in Django?

I have user reviews on my site. Each review has a rating of 1-5 stars. I want to print that many stars. How do I do it? I only see {% for X in Y %} which lets you iterate over a list, but not a certain number of times. ...

Django templates: value of dictionary key with a space in it

In a Django template, is there a way to get a value from a key that has a space in it? Eg, if I have a dict like: {"Restaurant Name": Foo} How can reference that value in my template. Pseudo-syntax might be: {{ entry['Restaurant Name'] }} ...

Displaying scraped results in Django template

I'm test building a scraping site with django. For some reason the following code is only providing one picture image where i'd like it to print every image, every link, and every price, any help? (also, if you guys know how to place this data into a database model so I don't have to always scrape the site, i'm all ears but that may be a...

Django - Is there a way to create a variable in the template?

I want to do this: {% for egg in eggs %} <p>{{ egg.spam }}</p> {% if egg.is_cool %} {% myvariable = egg %} // Possible in any way? {% endif %} {% endfor %} Pardon the JavaScript-style comment (it shows up as a comment on SO) ...

Does Django Have a Way to Auto-Sort Model Fields?

So basically, I've got a rather large Django project going. It's a private web portal that allows users to manage various phone-related tasks. Several pages of the portal provide a listing of Model objects to users, and list all of their attributes in a HTML table (so that users can visually look through a list of these items). The pro...

Django TemplateSyntaxError only on live server (templates exist)

I'm getting a strange error that only occurs on the live server. My Django templates directory is set up like so base.html two-column-base.html portfolio index.html extranet base.html index.html The portfolio pages work correctly locally on multiple machines. They inherit from either the root base.html or two-column-base.html. H...

Problem filling Django template in googleappengine Loader

I am trying to test a googleapengine project locally, but am getting errors loading templates: My settings.py contains TEMPLATE_LOADERS with Loader wrappers: e.g. django.template.loaders.filesystem.Loader but there is no Loader wrapper class in the bundled filesystem.py file within xx/google_appengine/lib/django/django/template/load...

View centric design with Django

Hi! I'm relatively new to Django and I'm designing a website that primarily needs usability experience, speaking of optimized CSS, HTML5 and UI stuff. It's very easy to use Django for data/Model centric design. Just designing a couple of Python classes and ./manage.py syncdb - there's your Model. But I'm dealing with a significant amou...

Are Django template tags cached?

I have gone through the (painful) process of writing a custom template tag for use in Django. It is registered as an inclusion_tag so that it renders a template. However, this tag breaks as soon as I try to change something. I've tried changing the number of parameters and correspondingly changing the parameters when it's called. It's c...