Dynamic path built for a .svg file using uuid and passing the constructed path to view not working

88 views
Skip to first unread message

Rahul

unread,
Jun 17, 2016, 6:25:37 AM6/17/16
to web2py-users
Hi All,
       I am using uuid to create new temporary files for PYGAL chart. Although I can see the file being created and available in the file system. Even I can view the file in the browser, however when I serialize the path variable to be passed to the view, I get an error - A 404 not found error is shown inside a frame in my view. How do I serialize the path at runtime to src= in the view such that it should take the path that I have constructed using dynamicLinechartpath.. ? Below is the code
 
unique_filename = (str(uuid.uuid4()) +'.svg')
##...other code
## This creates the file in the file system
linechart
.render_to_file(os.path.join(request.folder,'static/charts/' + unique_filename))

## Constructing the path to pass to the view
dynamicLinechartpath
= (""" "{{=URL(r=request, c='static', f='charts/""" + unique_filename + """')}}" """)



Calling the path in view -
<figure>
       
<embed type="image/svg+xml" src={{=dynamicLinechartpath}} />
 
</figure>

I have tried
src="{{=dynamicLinechartpath}}
but  it does not work.  Is this proper approach ? What am I doing wrong?
Here is what 'response.flash' shows me in my view when I try to check what is being passed. which I think is looking good.
"{{=URL(r=request, c='static', f='charts/bf094fa3-a711-4118-a3aa-89f647cca4f1.svg')}}"

Please suggest,
Rahul D.

Rahul

unread,
Jun 20, 2016, 1:55:53 AM6/20/16
to web2py-users
Hi All - Any updates to this issue ?

Rahul.

Nico de Groot

unread,
Jun 20, 2016, 2:48:48 AM6/20/16
to web2py-users
Please check the rendered html in the browser. Then you can see what's going on. Maybe you need the host=True in URL() to get a full path.

Nico de Groot

Rahul

unread,
Jun 20, 2016, 6:27:41 AM6/20/16
to web2py-users
Thanks! Nico, But it does not work. I used urllib to decode the dynamically passed url to 'utf8' however it seems like I would have to pass a few more iterations to normalize the url.
Here is what is shown when I inspect the element. &quot;  is the problem area.
 
<figure>
                                 
<embed type="image/svg+xml" src="{{=URL(r=request, c=&quot;static&quot;, f=&quot;charts_graphs/4a7c9543-26d3-4adf-bdba-a0b32a7f1b31.svg&quot;)}}" />
                               
</figure>


Thanks! Rahul

Nico de Groot

unread,
Jun 20, 2016, 7:25:51 AM6/20/16
to web2py-users
The {{=...}} is meant to be used inside the view. You are using it also in the controller. Just use the URL() there to get back a path as a string. Send the resulting var to the view as you are already doing.
If you inspect the rendered HTML you'll understand the difference.

Nico

Rahul

unread,
Jun 22, 2016, 3:05:19 AM6/22/16
to web2py-users
Hi Nico,
         Thanks! for your support - Here's how I was finally achieved it.
Hardcoded the partial path  as below in the controller
dynamicLinechartpath = ("""/ApplicationName/static/charts/""" + unique_filename )Enter code here...

In the view, you dont need to use the URL parameter -
DLC is passed to the view which is nothing but dynamicLinechartpath variable.

<!--  Line chart trial-->
                               
<figure>
                                 
<embed type="image/svg+xml" src="{{=DLC}}" />
                               
</figure>

This constructed the proper path in the view.

Thanks, Rahul

Nico de Groot

unread,
Jun 22, 2016, 5:28:12 AM6/22/16
to web...@googlegroups.com
Hi Rahul,

You're welcome. Remarks: The triple double quotes are for multiline strings. Just use one pair of double or single quotes. And you can remove the parentheses, not needed here. Less is more.

Nico
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/oUafNyAufTI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rahul

unread,
Jun 22, 2016, 8:29:34 AM6/22/16
to web2py-users
Yes.  That was code copied from my previous code for trial and error code stubs. Agreed - Less is more.

Rahul.
Hi Rahul,
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages