django-templates

Django templates stripping spaces?

為{幸葍}努か 提交于 2019-12-19 05:22:36
问题 I'm having trouble with Django templates and CharField models. So I have a model with a CharField that creates a slug that replaces spaces with underscores. If I create an object, Somename Somesurname, this creates slug Somename_Somesurname and gets displayed as expected on the template. However, if I create an object, Somename Somesurname (notice the second space), slug Somename__Somesurname is created, and although on the Django console I see this as <Object: Somename Somesurname> , on the

Problems with simple_tag array values in Django Template

大憨熊 提交于 2019-12-19 04:58:34
问题 I'm trying to pass an array to my template with a simple tag. I created my module under app/templatetags/pages_navigation.py and in my opinion the code should be alright: from django import template from pages.models import Page register = template.Library() @register.simple_tag(name='links') def pages_navigation(): pages = Page.objects.all() links = [['Events','/']] for page in pages: links.append([page.title, '/'+page.url]) return {'links':links} In my template I try to access links like

Firefox handles xxx.submit(), Safari doesn't … what can be done?

心已入冬 提交于 2019-12-19 04:49:16
问题 I'm trying to make a pull down menu post a form when the user selects (releases the mouse) on one of the options from the menu. This code works fine in FF but Safari, for some reason, doesn't submit the form. I re-wrote the code using jquery to see if jquery's .submit() implementation handled the browser quirks better. Same result, works in FF doesn't work in safari. The following snippets are from the same page, which has some django template language mixed in. Here's the vanilla js attempt:

Optimize django query to pull foreign key and django-taggit relationship

旧街凉风 提交于 2019-12-19 04:06:10
问题 I have a todo model defined below: class Action(models.Model): name = models.CharField("Action Name", max_length=200, unique = True) complete = models.BooleanField(default=False, verbose_name="Complete?") reoccurance = models.ForeignKey(Reoccurance, blank=True, null=True, verbose_name="Reoccurance") notes = models.TextField("Notes", blank=True) tags = TaggableManager() class Reoccurance(models.Model): label = models.CharField("Label", max_length=50, unique = True) days = models.IntegerField(

django template if condition

一个人想着一个人 提交于 2019-12-19 02:48:18
问题 got a question here. I have the following {% if form.tpl.yes_no_required == True %} <!-- path 1 --> {% else %} {% if form.tpl.yes_no_required == False %} <!-- path 2 --> {% endif %} {% endif %} The value for form.tpl.yes_no_required is None, but I was routed to path 2. Can anyone please explain why is this so? EDIT: if the value is none, i do not want it display anything. 回答1: You can't use the template language to test against what you think are constants, the parser is actually testing 2

Django Template inheritance: how many levels and what page to render

 ̄綄美尐妖づ 提交于 2019-12-19 00:26:10
问题 I would like to have some advice in constructing django template levels. Reading the docs, I do not understand how to create a template hierarchy structure with more than 2 levels. For example, I would like to create 3 levels of inheritance: base.html └── base_level2.html ├── level2_level3_1.html └── level2_level3_2.html This is my code: base.html First level {% block level2 %}{% endblock %} base_level2.html {% extends "base.html" %} {% block level2 %} Second level {% block level3_1 %}{%

Accessing Django OneToOneField in templates?

假装没事ソ 提交于 2019-12-18 18:51:18
问题 I have the following scenario. class A(models.Model): a = models.IntegerField() class B(models.Model): c = models.OneToOneField(A) d = models.DecimalField() In my templates, I have a list of objects A. In my template how do I access the attribute "d" from my template? Thanks. 回答1: class B(models.Model): c = models.OneToOneField(A, related_name='b') d = models.DecimalField() {{ a.b.d }} 来源: https://stackoverflow.com/questions/6676134/accessing-django-onetoonefield-in-templates

How to edit django-allauth default templates?

梦想的初衷 提交于 2019-12-18 15:09:30
问题 i'm using Django 1.10 and i want to add the allauth's app for login, signin, etc, to my website. I've installed allauth from pip, and tried to put the templates from allauth repository inside my templates folder and call them but i don't know how to make it work. 回答1: The correct answer can be found here: https://stackoverflow.com/a/31282443/4992248 Create yourproject/templates/allauth/account/ and paste here all templates you need to edit from /myproject/Lib/site-packages/allauth/templates

How to process two forms in one view?

可紊 提交于 2019-12-18 13:31:27
问题 I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views? regards chriss 回答1: Personally, I'd use one view to handle each form's POST. On the other hand, you could use a hidden input element that indicate which form was used <form action="/blog/" method="POST"> {{ blog_form.as_p }} <input type="hidden" name="form-type"

Django Template Tags in Views

杀马特。学长 韩版系。学妹 提交于 2019-12-18 11:56:18
问题 Hi I need to refresh my custom template tag --right_side.py-- via Ajax. Is there a way to import the template tag in the view and return it as HttpResponse because I don't want to give up my custom template tag (it works great in other pages) nor code a new view action which is really similar to it. Having a link to call with Ajax or loading it in the view inside if request.isAjax(): Are both fine for me. 回答1: I find it really useful when refreshing an area with ajax. So thought it would be