django-templates

bootstrap 3 wrap text content within div for horizontal alignment

*爱你&永不变心* 提交于 2019-12-03 10:24:20
My post title here could be misleading. first have a look at HTML i have currently: As you can see, each column's text content overflows to next column. Secondly, each of them is not horizontal aligned. (eg the link for view details does not align straight). I want them to be aligned straight irrespective of length of text. Here is my HTML code: (the content here is dynamically generated. so the no of items will vary). I use bootstrap 3 in my code. <div class="row" style="box-shadow: 0 0 30px black;"> <div class="col-6 col-sm-6 col-lg-4"> <h3>2005 Volkswagen Jetta 2.5 Sedan (worcester http:/

How to check if django template variable is defined?

廉价感情. 提交于 2019-12-03 10:22:10
I have a django template which is used from many views. The template has a block for messages used to notify user of anything that should take their attention. Whether a message is sent or not depends on the views. Some views may send a message variable to the template while others may not. view_1: message = "This is an important message" render_to_response("my_template.html", {'message':message, 'foo':foo, 'bar':bar}, context_instance = RequestContext(request)) view_2: message = "This is an important message" render_to_response("my_template.html", {'foo':foo, 'bar':bar}, context_instance =

How to make an object slider in django?

时光毁灭记忆、已成空白 提交于 2019-12-03 10:13:37
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, sizes=((200,200),(400,400))) title = models.CharField(max_length=100) author = models.CharField(max_length=100, blank=True) body = models.TextField() teaser = models.TextField('teaser', blank=True) created=models.DateTimeField(default=datetime.datetime.now) pub_date=models.DateTimeField(default=datetime.datetime.now) categories = models.ManyToManyField(Category,

How to split long line in Django template?

青春壹個敷衍的年華 提交于 2019-12-03 10:09:34
I have too long line in Django template {% for some_item, some_another_item, again_some_another_item_with_long_name in items %} How can I split it? Using \ or just splitting doesn't work. If you really want to keep those nasty long names, what I would do is: {% for a, b, c in items %} {% with a as some_item %} {% with b as some_another_item %} {% with c as again_some_another_item_with_long_name %} bla bla bla .. {% endwith %} {% endwith %} {% endwith %} {% endfor %} Andriy Sorochan You can use 'word wrap' or 'soft wraps' feature of your text editor. In the PyCharm if you search by soft you

Django, global template variables

99封情书 提交于 2019-12-03 09:57:57
I have a base template file (base.html) and every other template extends to it and generates content using its blocks. Certain variables, such as nav_obj, are used in the base template file. View: nav_obj = NavigationObject.objects.all() Base template: {% for object in nav_obj %} <a href="{{ object.link }}">{{ object.title }}</a> {% endfor %} At the moment, I need to pass nav_obj in every view. Is there any way to have this sent automatically? Write your own context processor . Inclusion tags might be a good-looking alternative to a context processor. eruciform There is an alternative,

Django: Displaying formset errors correctly

折月煮酒 提交于 2019-12-03 09:53:49
I have an inline formset for a model, which has a unique_together constraint. And so, when I input data, which doesn't fulfill this constraint, it displays: __all__Please correct the duplicate values below. The code, which does this is: {% for error in formset.errors %} {{ error }}<br/> {% endfor %} I don't much like the __all__ at the beginning of the error and it is quite clearly the dictionary key, so I tried: {% for key, error in formset.errors %} {{ key }}: {{ error }}<br/> {% endfor %} But then all I get is: __all__: {{ error }} won't display at all. So what's going on here? And how do I

Django - How to pass several arguments to the url template tag

折月煮酒 提交于 2019-12-03 09:47:51
In my urls.py I have: (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/section/(?P<slug>[-\w]+)/$', 'paper.views.issue_section_detail', {}, 'paper_issue_section_detail' ), and I'm trying to do this in a template: {% url paper_issue_section_detail issue.pub_date.year,issue.pub_date.month,issue.pub_date.day,section_li.slug %} but I get this error: TemplateSyntaxError Caught an exception while rendering: Reverse for 'paper_issue_section_detail' with arguments '(2010, 1, 22, u'business')' and keyword arguments '{}' not found. However, if I change the URL pattern to only require a single

Django-Template : Get Variables in a Tag block !

試著忘記壹切 提交于 2019-12-03 09:41:15
问题 I need to retrieve an optional number saved in DB , to a custom template tag i made . which to retrieve , a variable ( a photo ID ) included in this Gallery . within the gallery loop . {% get_latest_photo {{photo.id}} %} How to accomplish that ?! P.s : I know that can be done with inclusion tag , but in the present time how to make it fix this one ! Edit the template html file : {% for album in albumslist %} {% get_latest_photo photo.id %} {% for photo in recent_photos %} <img src='{%

django template if or statement

无人久伴 提交于 2019-12-03 09:31:02
Basically to make this quick and simple, I'm looking to run an XOR conditional in django template. Before you ask why don't I just do it in the code, this isn't an option. Basically I need to check if a user is in one of two many-to-many objects. req.accepted.all and req.declined.all Now they can only be in one or the other (hence the XOR conditional). From the looking around on the docs the only thing I can figure out is the following {% if user.username in req.accepted.all or req.declined.all %} The problem I'm having here is that if user.username does indeed appear in req.accepted.all then

How to loop over form field choices and display associated model instance fields

青春壹個敷衍的年華 提交于 2019-12-03 09:23:13
问题 I have a ModelForm with a multiple choice field. The choices are populated instances of Hikers belonging to a specific Club. I want to customize the way my form displays, by displaying the choices in a table where the 1st column contains checkboxes, and a few more columns display the details of each hiker. So for example the columns are (checboxes, name, age, favourite hiking trail). I'm not sure how to approach this. How do I access and display the form field choices with it's associated