django-templates

increment a variable in django templates

谁说我不能喝 提交于 2019-12-03 06:47:55
All, How Can we increment a value like the following in django templates, {{ flag =0 }} {% for op in options %} {{op.choices}}<input type="radio" name="template" id="template" value="template{{flag++}}"/> {% endfor %} thanks.. I don't think it's intended you should alter data in your templates. For in your specific case, you could instead use the forloop.counter variable. For example: {% for op in options %} {{op.choices}}<input type="radio" name="template" id="template{{forloop.counter}}" value="template{{forloop.counter}}"/> {% endfor %} Also note that I added that number to the id

Looking for a resource which provides django templates [closed]

 ̄綄美尐妖づ 提交于 2019-12-03 06:19:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm pretty handy with django and python but I'm terrible at the "visual" aspect of the web-design. Even after quite a bit of google-ing I haven't been able to find any sort of resource that has download-able templates complete with css, images, etc. that could be used to set up a basic website easily. I'm looking

how to render only part of html with data using django

邮差的信 提交于 2019-12-03 06:13:55
问题 I am using ajax to sort the data which came from search results. Now I am wondering whether it is possible to render just some part of html so that i can load this way: $('#result').html(' ').load('/sort/?sortid=' + sortid); I am doing this but I am getting the whole html page as response and it is appending the whole html page to the existing page which is terrible. this is my views.py def sort(request): sortid = request.GET.get('sortid') ratings = Bewertung.objects.order_by(sortid)

django: guidelines for speeding up template rendering performance

こ雲淡風輕ζ 提交于 2019-12-03 06:10:39
How would I go about speeding up Django template rendering? My template takes about 1-2 seconds or so to render, after the view function fully computes whatever it needs to. I've already attempted to perform all database access in the view, such that the template only hits RAM and not the DB engine. I do have a lot of include s - could there be an issue there? I just spent a good deal of time optimizing my django templating code. Below are optimization guidelines that worked for me, but depending on your setup, you may not get as significant of a speedup. Feed the Templating Engine unicode ,

Django Templates: Comparing current url with {% url xyz %}

£可爱£侵袭症+ 提交于 2019-12-03 06:09:50
问题 I am trying change the active selection of my navigation links based on the current page where the user is at. I am trying to do omething like this: <li {% if request.get_full_path == {% url profile_edit_personal %} %}class="current"{% endif %}><a href="{% url profile_edit_personal %}">Personal Details</a></li> Alternatively, I know I could define do something like this: <li class="{% block current %}{% endblock %}"><a href="{% url profile_edit_personal %}">Personal Details</a></li> and add a

Django template object type

妖精的绣舞 提交于 2019-12-03 05:51:11
Alright, here's my situation. I've got an array of generic objects that I'm iterating over in a django template. Those objects have a number of subclasses and I want to figure out in the template which subclass I'm dealing with. Is this possible? Advisable? The code might look something along the lines of (where the if statements include some imaginary syntax): <table> <tr> <th>name</th> <th>home</th> </tr> {% for beer in fridge %} <tr> <td> {{ beer.name }} </td> <td> {% if beer is instance of domestic %}US of A{% endif %} {% if beer is instance of import %}Somewhere else{% endif %} </td> </tr

How to get object from PK inside Django template?

让人想犯罪 __ 提交于 2019-12-03 05:40:26
Inside django template, I would like to get object's name using object's pk. For instance, given that I have pk of object from class A , I would like to do something like the following: {{ A.objects.get(pk=A_pk).name }} How can I do this? From the docs on The Django Template Language : Accessing method calls : Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display. So you see, you should be

How to include templates dynamically in Django using “include” tag

五迷三道 提交于 2019-12-03 05:00:36
问题 I have 10 html files with the names 1.html, 2.html ..etc What I want is according to a variable, a certain file should be included in the template. e.g. {% if foo.paid %} {% include "foo/customization/{{ foo.id }}.html" %} {% endif %} Is this possible ? Cause the foo.id is not being translated before the includes tag works. As a result its giving a error. How can this issue be handled in a different way ? Should I create a custom template tag for this ? 回答1: You can do it with add filter and

How do you use get_context_data with TemplateView in Django [closed]

二次信任 提交于 2019-12-03 04:44:02
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to do something like this: class AboutView(TemplateView): template_name = 'about.html' def get_context_data(self, **kwargs): context = super(AboutView, self).get_context_data(**kwargs) context['dahl

tree structure of parent child relation in django templates

拜拜、爱过 提交于 2019-12-03 04:40:34
问题 how do i implement the tree structure in django templates with out using django-mptt. i have model. class Person(TimeStampedModel): name = models.CharField(max_length=32) parent = models.ForeignKey('self', null=True, blank=True, related_name='children') now i want .. Parent Child 1 subchild 1.1 subchild 1.2 nextsubchild 1.2.1 Child 2 Child 3 there names should be click able to show their profile. 回答1: from Django while loop question and http://docs.djangoproject.com/en/dev/howto/custom