django-templates

Could not parse the reminder in django

无人久伴 提交于 2019-12-06 15:24:07
I want to add a script tag inside a jquery template. So am referring to this link . It tells to close the inner script tag in the following way : <script id="filaVideoTemplate" type="text/x-jQuery-tmpl"> <!-- Some HTML here --> <script type="text/javascript"> <!-- Some javascript here --> {{html "</sc"+"ript>"}} </script> I tried it, but django shows this error: Could not parse the remainder: '" < /sc"+"ript>"' from 'html "< /sc"+"ript>"' .How can I do this django. Is there any specific solution in django for this? { and } are reserved characters in Django templates, so you need to use

How do I initiate values for fields in a form for editing in a template

谁说我不能喝 提交于 2019-12-06 15:08:27
I understand that you can use the initiate parameter for a Form class from this question . I am creating an edit form and I'm trying to figure out how to initiate values from a pre-existing object. Do I do it in the template level or in the view level (I don't even know how to do it in the template level)? Or maybe I need to pass the actual object to the form and initiate in the form level? What is the best practice? EDIT: For @Bento: In my original Form , I'm doing something like this class OrderDetailForm(forms.Form): work_type = forms.ChoiceField(choices=Order.WORK_TYPE_CHOICES) note =

Using both sort & filter on a QuerySet

和自甴很熟 提交于 2019-12-06 14:58:27
I have a list of userprofiles that I want to be able to sort and filter. I have been able to do this manually, by manually typing in the URLs, but I haven't been able to code the template page to allow the persistence of a previously-applied filter or sort. Here is the url and template code that I currently have -- # in urls url(r'^talent/filter\:(?P<position>[A-Za-z]+)/sort\:(?P<sort>[A-Za-z]+)$', 'talent_filter', name='talent_filter_sort'), url(r'^talent/filter\:(?P<position>[A-Za-z]+)/$', 'talent_filter', name='talent_filter'), url(r'^talent/sort\:(?P<sort>[A-Za-z]+)/$', 'talent_sort', name

Django: List Products of each Categories in a page

本小妞迷上赌 提交于 2019-12-06 14:12:38
问题 I have a few categories and I would like to list the products per category in the format below (categories is an FK to products): Category 1 bunch of products .... Category N bunch of products I have tried many ways but so far I only get the categories but not the products to show in my HTML. models.py class Category(models.Model): title = models.CharField(max_length=225) slug = models.SlugField(unique=True, blank=True, null=True) def __str__(self): return self.title def get_absolute_url(self

Why does django not use my SHORT_DATE_FORMAT with date template tag?

安稳与你 提交于 2019-12-06 13:50:56
I have troubles understanding why django doesn't use my SHORT_DATE_FORMAT in templates when I specify it for the date template tag. My settings are: TIME_ZONE = 'Australia/Melbourne' SHORT_DATE_FORMAT = 'd/m/Y' LANGUAGE_CODE = 'en-AU' USE_I18N = True USE_L10N = True USE_TZ = True In my template: {{ asset.upload_date|date:"SHORT_DATE_FORMAT" }} I would expect '21/01/2014' but I get '01/21/2014'. djangonaut It's actually due to USE_L10N=True + Django still not having a locale conf for Australia ( en-au/en_AU ) which specifies d/m/Y . Bit of an surprise. But it will be there with the release of 1

Django: How to include a view from within a template

瘦欲@ 提交于 2019-12-06 13:29:18
I'm new to django and I was wondering what is the best/recommend approach to include a view (with certain logic, and its resulting HTML) from within a template. My concrete example is as follows: I have a model which is: class City(models.Model): name = models.CharField(max_length=200) class Place(models.Model): city = models.ForeignKey(City) name = models.CharField(max_length=200) state = models.IntegerField() So I need a view to show each city and it's places. Each place should be rendered in a different way depending on its state. Each different way is very different and will probably need

Django Templates: Display a date only if it's in the future

点点圈 提交于 2019-12-06 12:21:31
问题 How do I compare dates in a Django template? I thought of several possible avenues: Send today's date in the context to be compared at the template Create my own template tag Have some logic in the view to only pass the date if it's in the future Although the last option seems easier, I rather leave the display logic in the template than in the view. I also do not want to pass something that seems so trivial like today's date in the template context. Perhaps someone has another option or

django 'if' statement improperly formatted

≡放荡痞女 提交于 2019-12-06 12:16:27
问题 Im getting strangest error in django so far: 'if' statement improperly formatted Template that raises the error is this: {% if diff >= 0 %} <span class="pos">+{{ diff }} {% else %} <span class="neg">-{{ diff }} {% endif %} </span> <span>{{ a }}</span> view that has a and diff in context is this: def add(request, kaart_id): if request.is_ajax() and request.method == 'POST': x = Kaart.objects.get(id=kaart_id) x.pos += 1 x.save x = Kaart.objects.get(id=kaart_id) from django.utils import

Django no module named utils

天涯浪子 提交于 2019-12-06 11:59:23
I know this question has been asked before but after looking into it I can't help but feel I missed something. So I previously had a problem getting django-compressor installed but after a bit of struggling i managed to get it installed. When I run my django application though it stops on execute_from_command_line(sys.argv) in my manage.py and throws this error: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command_line(sys.argv) File "C:\Users\PCDOM\Desktop\Power\pm_app\env\lib\site-pac kages\django\core\management\_

book count per author for filtered book list in django

旧街凉风 提交于 2019-12-06 11:37:59
问题 Short question. I have two models: class Author(models.Model): name = models.CharField(max_length=250) class Book(models.Model): title = models.CharField(max_length=250) author = models.ManyToManyField(Author) One view: def filter_books(request): book_list = Book.objects.filter(...) How can I display in template next content: Authors in selected books: Author1: book_count Author2: book_count ... 回答1: Let's build the query step by step. First, get the authors who have a book in book_list .