Questions tagged [django-templates]

Questions about the template engine of Django, which is intended to separate the presentation of a document from its data.

A Django template is a string of text that is intended to separate the presentation of a document from its data. A template defines placeholders and various bits of basic logic — tags — that regulate how the document should be displayed. Usually, templates are used for outputting HTML but Django templates are equally capable of generating any text-based format.

The two key features of Django templates are that they are not, on their own, very powerful (in particular, no functions may be called with parameters), and a flexible, extensible tag system which allows users to break out of its constraints. This tends to prevent logic other than presentation logic from creeping into templates.

An example template built with the Django template language.

<html>
    <head>
        <title>{{ site.title }}</title>
    </head>
    <body>
        <h1>{{ site.greeting }}</h1>
        <ul>
            {% for item in menu_items %}
            <li>{{ item|upper }}</li>
            {% endfor %}
        </ul>
    </body>
</html>

See the official documentation for more details.

19491 questions
4
votes
2 answers

Jquery .load() does not work within Django template

The thing I want to do is to render a html "a" file in template. And use jquery .load() to embedded other html files in this a.html. But I failed with my following code. The following is my a.html content: {% load staticfiles %} …
Chang May
  • 165
  • 1
  • 10
4
votes
2 answers

How to make an object slider in django?

I have written a simple article publishing site in Django 1.8. Here is the model that I'd like to slide: class Article(models.Model): nid = models.IntegerField(default=0) headimage = ImageWithThumbsField(upload_to='images', blank=True,…
Jand
  • 2,527
  • 12
  • 36
  • 66
4
votes
1 answer

How to initialize the variable and increment it in Django template?

I am trying to initialize the variable and increment it in the for loop but I'm getting the following error: Invalid block tag: 'set', expected 'endspaceless' This is my code: {% spaceless %} {% set…
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
4
votes
1 answer

Can I add or update a new variable after render in django template

I've been trying to add or update a variable in the templete before the first render. I have an Ajax request that sends a POST request which works fine, but when I tried to return the new variable, destinations, to the same page/template,…
4
votes
2 answers

How to retrieve the first 10 elements in a template variable?

In my template I have a loop like this: {% 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 ?
xRobot
  • 25,579
  • 69
  • 184
  • 304
4
votes
1 answer

How to get Object as String in Django?

I'm trying to do a very simple thing but I couldn't find how to. I have this function defined in my model class : def __unicode__(self): return "Object name = " + self.name so in a template page, or in a views.py, I want to get this string. in…
jeff
  • 13,055
  • 29
  • 78
  • 136
4
votes
1 answer

Django- NoReverseMatch. Reverse for '' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I'm trying to pass a value from my template file to a function in the views.py file in Django. My project structure is as follows- myproject/ manage.py myproject/ __init__.py urls.py wsgi.py views.py …
deathstroke
  • 526
  • 12
  • 33
4
votes
1 answer

django form and title property

i need to render my forms with the property "title" for jquery validation, how ill render my forms in this way? Thanks guys
Asinox
  • 6,747
  • 14
  • 61
  • 89
4
votes
3 answers

Django TemplateResponseMixin

I am new to Django and trying to get my head around mixins with class based views. As per my understanding, mixins are classes containing a combination of methods from other classes(similar to multiple inheritance). I am following the official…
Blackhole
  • 107
  • 1
  • 5
4
votes
1 answer

how to integrate django app forms in djangocms plugins

I wrote an simple django app to store e-mail adresses if the user fills in a form. Everything worked fine but when i followed this tutorial to integrate my app in django-cms i noticed that my form is not displaying in the Plugin as it did before i…
Lepus
  • 567
  • 6
  • 22
4
votes
1 answer

Django Admin stylesheets won't load on production server

Django's stylesheets for it's built-in Admin site aren't being loaded on my production server which runs Django 1.6. I can see that many other people have encountered this problem and I've tried all the solutions that have been provided to them but…
Jim
  • 13,430
  • 26
  • 104
  • 155
4
votes
1 answer

Rowspan and grouping in Django template

I have many rows in a queryset. Many of the rows share the same value in two fields. I want to show the entire queryset in a table but I don't want to print those values which are the same multiple times. My output would be something like mood,…
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
4
votes
1 answer

Django Can't Find App Templates

I'm working through the official django 1.7 tutorial found here. Everything is going smoothly except django can't find the templates for apps. It finds templates that I put under workspace/mysite/templates but not under…
Longblog
  • 821
  • 2
  • 11
  • 19
4
votes
4 answers

how to combine a template from other processed templates?

I have a django project pro1 with several apps: app1, app2, app3 and so on. I want to display some top level template that contains blocks from each and every app: example_base_template.html: [header /] [left nav bar]{{ app1 rendered template…
chriss
  • 4,349
  • 8
  • 29
  • 36
4
votes
2 answers

Django template inline jQuery not working

Trying to get inline jQuery in my template working so that I can use django url tags in AJAX calls later. But I can't get the javascript to work. In my subpage I extend my index page which has all my javascript and jQuery libraries. {% extends…
Kyle Calica-St
  • 2,629
  • 4
  • 26
  • 56
1 2 3
99
100