django-templates

How to pass HTML to an included template

爷,独闯天下 提交于 2019-12-08 13:25:04
问题 Using Djangos template language I would like to pass HTML generated through the template language into an included template like in the following simplified example: field.html <input name="input_name" /> <div>{{ input_desc_html }}</div> form.html {% with input_name="test" input_desc_html=... %} ... should read {% for this in that %} {{ this }} {% endfor %} {% include 'field.html' %} {% endwith %} Obvioulsy there is something missing at ... and I do not know how to advance from here. Is this

Getting MEDIA images on Amazon S3 server on template

此生再无相见时 提交于 2019-12-08 12:55:20
问题 The static files (css, js, images) are serving from local whilst media files (uploaded images and videos) are on Amazon S3 server in my project. I can upload media files to Amazon S3 without any problem. But I cannot get the URL's of the files on templates. I have tried the static files and it worked: (But static files will be on the local) {% load static from staticfiles %} {% static "imagename.png" %} And how can I do it for MEDIA files? {% media "imagename.png" %} # maybe something like

Django: static files in a 404 template

耗尽温柔 提交于 2019-12-08 12:04:15
问题 How to include stylesheets and images into a 404 page template using the default view? I created a 404.html file in the root of the site's templates directory: <!DOCTYPE html> <html> <head> {% load static %} <link rel="stylesheet" href="{% get_static_prefix %}css/404.css" /> </head> <body class="page-404"> <p>Not found.</p> </body> </html> Ironically, the 404.css is not found. The 404.css file is located in one of the apps' static directory. The server is manage.py runserver . On every other

cell color Django-Tables2

[亡魂溺海] 提交于 2019-12-08 12:02:49
问题 Question: Where do I edit my django code to change the background color of individual cells based on business logic? In my views.py I have logic that captures the max value of column 'pts': def show_teams(request): reg = Teamoffense.objects.filter(~Q(rk='RK')) pts = Teamoffense.objects.filter(~Q(pts='PTS')).values('pts') seq = [item['pts'] for item in pts] maxseq = max(seq) table = SimpleTable(reg) table_to_report = RequestConfig(request).configure(table) if table_to_report: return create

How to create Dependent dropdown in Django forms?

爱⌒轻易说出口 提交于 2019-12-08 11:33:39
问题 I want to create dependent dropdowns. For example, if someone selects book from the first dropdown, second dropdown should have chapter listed under that book. I have achieved it using HTML / Jquery / AJAX. But i am now interested to achieve same using Django forms. If anyone have idea, please share it. Thank you in advance. 回答1: If you are not afraid of adding dependencies: django-select2 has an implementation of chained selects, which can be configured using the django form API. Example

django crispy forms overriding layout objects templates ignored

懵懂的女人 提交于 2019-12-08 11:31:31
问题 I applied this thus I have self.helper.layout = Layout( Field( 'title', template="mytemplate.html" ) , As result my template is not rendered helper.field_template is None in below code : (C:\myapp\lib\crispy_forms\templatetags\crispy_forms_filters.py): @register.filter(name='as_crispy_field') def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""): """ Renders a form field like a django-crispy-forms field:: {% load crispy_forms_tags %} {{ form.field|as_crispy

How to create an BytesIO img and pass to template

混江龙づ霸主 提交于 2019-12-08 10:26:45
问题 AIM I am attempting to: Create a histogram, Store it temporary memory, Pass the image to the template. I am having trouble with Step 3 above. I suspect that I am making a simple and fundamental error in relation to passing the context data to the template. ERROR HTML is rendering with a broken image tag. CODE Views.py class SearchResultsView(DetailView): ... def get(self, request, *args, **kwargs): self.get_histogram(request) return super(SearchResultsView, self).get(request, *args, **kwargs)

Implement regex in django template

你离开我真会死。 提交于 2019-12-08 10:24:18
问题 I am making the navigation of the page as active by checking if the url matches with the current url. <li> {% url 'blog' as blog_url %} <a href="{{blog_url}}" {% if request.get_full_path == blog_url %}class="active"{% endif %}>Blog</a> </li> Now I am using pagination, which when going to different page results in url being like this: From /blog/ to /blog/?page=2 /blog/?page=3 And the above code does not work. So is there anyway to use regex in the template to get anything (like /blog/* ) and

Display profile pic from model in template in django

a 夏天 提交于 2019-12-08 09:48:14
问题 I want to insert the user's image in the img src field.But I'm not able to do it. My code: models.py class allusers(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) avatar = models.ImageField(upload_to='retest/static/images/') views.py u = User.objects.get(username=username) tempate <img src={{ u.allusers.avatar }} 回答1: 1, register static and media in settings correct way . MEDIA_URL = '/media/' MEDIA_ROOT = '/srv/django/myproject/src/myproject/media' STATIC_URL = '

Jinja / Django for loop range not working

人走茶凉 提交于 2019-12-08 09:45:18
问题 I'm building a django template to duplicate images based on an argument passed from the view; the template then uses Jinja2 in a for loop to duplicate the image. BUT, I can only get this to work by passing a list I make in the view. If I try to use the jinja range, I get an error ("Could not parse the remainder: ..."). Reading this link, I swear I'm using the right syntax. template {% for i in range(variable) %} <img src=...> {% endfor %} I checked the variable I was passing in; it's type int