Webcomponents in Django

318 views
Skip to first unread message

Timothy W. Cook

unread,
Nov 19, 2014, 6:53:55 AM11/19/14
to django...@googlegroups.com

I have a Django app that I want to include a UI similar to the Polymer designer https://www.polymer-project.org/tools/designer/ 
Source code here:  https://github.com/twcook/TdV-app-designer/tree/tdv  plus the components installed via bower. 


I have built this designer as a standalone app and it works great using  python -m SimpleHTTPServer 

I have the code included in the Django app templates directory, renamed index.html to designer.html 

I have a url entry: 

url(r'^designer/', (DesignerView.as_view()), name='designer')

I have a view:

class DesignerView(TemplateView):
    template_name = 'TdV-app-designer/designer.html'


and I have tried using the {% verbatim %} {% endverbatim %} tags to wrap the code (the entire file, just the body, just the <designer-element id="designer"></designer-element> tags, etc.) all to no success. 

What happens is that the server begins recursively calling the custom element.

​So I get: 

[19/Nov/2014 09:46:41] "GET / HTTP/1.1" 200 12867
[19/Nov/2014 09:46:43] "GET /designer/ HTTP/1.1" 200 10193
[19/Nov/2014 09:46:43] "GET /designer/components/platform/platform.js HTTP/1.1" 200 10196
[19/Nov/2014 09:46:44] "GET /designer/elements/designer-element/designer-element.html HTTP/1.1" 200 10193
[19/Nov/2014 09:46:44] "GET /designer/elements/designer-element/components/platform/platform.js HTTP/1.1" 200 10193
[19/Nov/2014 09:46:44] "GET /designer/elements/designer-element/elements/designer-element/designer-element.html HTTP/1.1" 200 10193
[19/Nov/2014 09:46:44] "GET /designer/elements/designer-element/elements/designer-element/components/platform/platform.js HTTP/1.1" 200 10193
[19/Nov/2014 09:46:44] "GET /designer/elements/designer-element/elements/designer-element/elements/designer-element/designer-element.html HTTP/1.1" 200 10194

...

it continues until timeout and probably forever until the server runs out of memory. 

Anyway, I have no idea what this is telling me. 

Any hints as to where the problem is and/or how to fix it?

Thanks,
Tim







 

============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Avraham Serour

unread,
Nov 19, 2014, 7:54:47 AM11/19/14
to django...@googlegroups.com
looks like the html rendered is making the recursive requests, are you using {% static %} and {% url 'designer' %} ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3XdmJmaPmjpGQe0UMXBwk0mhsawbdk3qynxRHwQhW6rsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Timothy W. Cook

unread,
Nov 19, 2014, 8:03:06 AM11/19/14
to django...@googlegroups.com
At the top of the both the main file where designer is called from and at the top of designer.html I have:
{% load staticfiles i18n %}

The call to the designer template is in a list with other calls that work fine:

<li><a href="{% url 'designer' %}">designer</a></li>

Thanks,
Tim



For more options, visit https://groups.google.com/d/optout.



--

Avraham Serour

unread,
Nov 19, 2014, 9:11:19 AM11/19/14
to django...@googlegroups.com
the line you posted is not a call to any template, it translates to a url address given the view name.

the top line means that the staticfiles module is loaded, you need that in order to use it in the template below, my question is if you actually use it, how do you point to the js file for example?

Timothy W. Cook

unread,
Nov 19, 2014, 9:15:21 AM11/19/14
to django...@googlegroups.com
What I am looking for is not necessarily an answer, since there is probably very few people that have tried this.  I am hoping that someone can give me an idea 'how to troubleshoot' this issue.  How do I break this down into steps to even see what is happening?  Since platform.js and designer-element.html are both returning 200 even though the url gets longer with each recursion; seems strange to me.

Thanks,
Tim
 

Timothy W. Cook

unread,
Nov 19, 2014, 9:18:40 AM11/19/14
to django...@googlegroups.com
On Wed, Nov 19, 2014 at 12:10 PM, Avraham Serour <tov...@gmail.com> wrote:
the line you posted is not a call to any template, it translates to a url address given the view name.

the top line means that the staticfiles module is loaded, you need that in order to use it in the template below, my question is if you actually use it, how do you point to the js file for example?


​Ah, okay.  The js file is ​called in the header of designer.html 
<script src="components/platform/platform.js"></script>

then the designer-element.html is imported:
<link rel="import" href="elements/designer-element/designer-element.html"> 


except the file is named designer.html vs. index.html  

Thanks,
Tim






 

For more options, visit https://groups.google.com/d/optout.

Timothy W. Cook

unread,
Nov 19, 2014, 11:00:46 AM11/19/14
to django...@googlegroups.com
Maybe I bit off too much to start.  IT looks like this may be a better place to start. 

... and not running the Django development server. 

Timothy W. Cook

unread,
Nov 19, 2014, 11:56:10 AM11/19/14
to django...@googlegroups.com
Progress:  I moved the Polymer code tree to my static directory and replaced the URL with

<li><a href="{{STATIC_URL}}TdV-app-designer/designer.html">designer</a></li> 

This at least lets me load the designer.  

Now on to see if I can build ajax calls to class based views or maybe there is another way? 



Cheers,
Tim
 

Peter of the Norse

unread,
Dec 18, 2014, 2:13:59 PM12/18/14
to django...@googlegroups.com
On 11/19/2014 7:18 AM, Timothy W. Cook wrote:
> then the designer-element.html is imported:
> <link rel="import"
> href="elements/designer-element/designer-element.html">

Here's your problem. This is a relative link, so the current directory
gets used as the base, and it tries to load
http://127.0.0.1/designer/elements/designer-element/designer-element.html.
That matches
> url(r'^designer/', (DesignerView.as_view()), name='designer')
because there's not a $ at the end of the pattern.

And it loads the page again. That page also has the same relative link,
but this time in a different file, so it creates the new link as
http://127.0.0.1/designer/elements/designer-element/elements/designer-element/designer-element.html
and the process starts all over again.

This isn't a Django problem but an HTML problem.

--
Peter of the Norse

Reply all
Reply to author
Forward
0 new messages