These are chat archives for django/django

28th
Nov 2018
matrixbot
@matrixbot
Nov 28 2018 05:23 UTC
mch Before learning django, I made a single plain index.html page with bootstrap (and static resources). Now, i want to serve it alongside my django /blog/ webapp. What is the best method?
Peter Bittner
@bittner
Nov 28 2018 08:25 UTC

Simply add the HTML file as a template and use it with Django (as you would a template). Simple as that.

Afterwards, step-by-step, you will want to replace the references to all static files (CSS, JavaScript, etc.) the typical Django way (using staticfiles).

Elisha Kingdom
@elshaddae
Nov 28 2018 10:08 UTC
Hello everyone, please help; I am trying to enable uploading multiple images in one classified post. I am using a generic class-based view, CreateView, but the formset for images are not rendered in my html, only the ClassifiedForm and the submit/publish button
matrixbot
@matrixbot
Nov 28 2018 16:28 UTC
mch Peter Bittner (Gitter): thanks, so should I initialize a new index django app and go through the process you described or will it be better performance-wise to rewrite all my /blog/ urls.py urlpatterns and stick the index template into my /blog/ webapp ?
Muhammad Bandawa
@mdnur89
Nov 28 2018 18:27 UTC
@AJ okay, I'm sorry.. thought that as I'm working on a django project thats implementing some some npm packages that I'm having problems with I would get help here aswel. Thanks for your advice.
lekan
@horlahlekhon
Nov 28 2018 23:21 UTC

hello....goodday .....am i created a template filter in django , but when i use it i get

TemplateSyntaxError
Exception Value:     

Invalid filter: 'multiply'

am kinda new to django , kindly help...thanks

fsecada01
@fsecada01
Nov 28 2018 23:21 UTC
please provide the full error log from the shell
lekan
@horlahlekhon
Nov 28 2018 23:24 UTC

this is the filter i wrote :

from django.template import Library

register = Library()


def multiply(value, arg) :
    return value * arg

multiply = register.filter(name="multiply")

this is the error:

TemplateSyntaxError at /polls/posts

Invalid filter: 'multiply'

Request Method:     GET
Request URL:     http://localhost:8000/polls/posts?page=1
Django Version:     2.1.3
Exception Type:     TemplateSyntaxError
Exception Value:     

Invalid filter: 'multiply'

Exception Location:     /home/user/.local/lib/python3.7/site-packages/django/template/base.py in find_filter, line 569
Python Executable:     /usr/local/bin/python3.7
Python Version:     3.7.1
Python Path:     

['/home/user/Documents/workspace/pythonVirtualEnv/newApp/mysite',
 '/usr/local/lib/python37.zip',
 '/usr/local/lib/python3.7',
 '/usr/local/lib/python3.7/lib-dynload',
 '/home/user/.local/lib/python3.7/site-packages',
 '/usr/local/lib/python3.7/site-packages']

Server time:     Wed, 28 Nov 2018 23:11:54 +0000


Error during template rendering

In template /home/user/Documents/workspace/pythonVirtualEnv/newApp/mysite/polls/templates/polls/posts.html, error at line 42
Invalid filter: 'multiply'
32                 <tr>
33                     <td>{{ post.post }}</td>
34                 </tr>
35                 {% endfor %}
36             </tbody>
37             </table>
38                 {% if is_paginated %}
39                   {% comment %} {% pagination paginator.page %} {% endcomment %}
40                   <div class="pagination-area mt-50">
41                 <div class="list-page-2">
42                     <p>Items {{ page_obj.number|multiply:"5" }}-{% widthratio page_obj.number 1 5%} of {{ page_obj.paginator.count}}</p>
43                 </div>
44                 <div class="page-number">
45                     <ul>
46                         {% if page_obj.has_previous %}
47                         <li><a href="?page={{page_obj.previous_page_number}}" class="angle"><i class="fa fa-angle-left"></i><</a></li>
48                         {% else %}
49                         <li><a  class="disable angle"><i class="fa fa-angle-left"></i></a></li>
50                         {% endif %}
51                         {% for i  in paginator.page_range  %}
52                             {% if page_obj.number == i %}
fsecada01
@fsecada01
Nov 28 2018 23:34 UTC
there's an extra whitespace in your multiply function. Delete that and see if it fixes the problem. Also, consider getting a Pep8 plugin for your IDE
lekan
@horlahlekhon
Nov 28 2018 23:36 UTC
It did not, same error
fsecada01
@fsecada01
Nov 28 2018 23:37 UTC
5 is being written as string, not as an Int
lekan
@horlahlekhon
Nov 28 2018 23:40 UTC
i have tried to change it to an int literal it didnt work too; and since the docs said to wrap it with quotes......
Peter Bittner
@bittner
Nov 28 2018 23:52 UTC

mch Peter Bittner (Gitter): thanks, so should I initialize a new index django app and go through the process you described or will it be better performance-wise to rewrite all my /blog/ urls.py urlpatterns and stick the index template into my /blog/ webapp ?

It really depends. Maintenance-wise, adding the HTML to your templates and an entry in your urlpatterns should suffice. If you want to (be able to) reuse the HTML you may want to make a separate Django app.

I don't think "performance" (i.e. execution speed) is relevant in this context.