The path '/scarica_file' was not found.

View: New views
4 Messages — Rating Filter:   Alert me  

The path '/scarica_file' was not found.

by luca72 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello i have write this:

def crea_link_azioni_file(musica_obj):
    from elementtree.ElementTree import Element
    span=Element("span")
    link1 =Element('a', href='/scarica_file?ID=%d' %musica_obj.id)
    link1.text='Scarica'
    span.append(link1)
    link2=Element('a', href='/index')
    link2.text='|Indice'
    span.append(link2)
    return span

and than:

@expose()
    def scarica_file(self, ID):
        from cherrypy.lib.cptools import serve_file
        import os
        dir_corrente = os.getcwd()
        b= Musica.get(ID)
        nome = b.nome_file
        nome_band = b.band
        return serve_file('/static/'+nome_band+'/'+nome,"application/x-
download", "attachment")

and i get this error:
age handler: <bound method Root.scarica_file of <tg.controllers.Root
object at 0xa8d666c>>
Traceback (most recent call last):
  File "/home/luca72/webapps/tg/lib/python2.5/CherryPy-2.3.0-py2.5.egg/
cherrypy/_cphttptools.py", line 121, in _run
    self.main()
  File "/home/luca72/webapps/tg/lib/python2.5/CherryPy-2.3.0-py2.5.egg/
cherrypy/_cphttptools.py", line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in scarica_file
  File "/home/luca72/webapps/tg/lib/python2.5/TurboGears-1.0.4.4-
py2.5.egg/turbogears/controllers.py", line 365, in expose
    *args, **kw)
  File "<string>", line 5, in run_with_transaction
  File "/home/luca72/webapps/tg/lib/python2.5/TurboGears-1.0.4.4-
py2.5.egg/turbogears/database.py", line 356, in so_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/home/luca72/webapps/tg/lib/python2.5/TurboGears-1.0.4.4-
py2.5.egg/turbogears/controllers.py", line 380, in <lambda>
    mapping, fragment, args, kw)))
  File "/home/luca72/webapps/tg/lib/python2.5/TurboGears-1.0.4.4-
py2.5.egg/turbogears/controllers.py", line 408, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/home/luca72/webapps/tg/lib/python2.5/TurboGears-1.0.4.4-
py2.5.egg/turbogears/errorhandling.py", line 72, in try_call
    return func(self, *args, **kw)
  File "/home/luca72/webapps/tg/tg/controllers.py", line 349, in
scarica_file
    return serve_file('/static/'+nome_band+'/'+nome,"application/x-
download", "attachment")
  File "/home/luca72/webapps/tg/lib/python2.5/CherryPy-2.3.0-py2.5.egg/
cherrypy/lib/cptools.py", line 206, in serveFile
    raise cherrypy.NotFound()
NotFound: (404, "The path '/scarica_file' was not found.")

If for example i change de def scarica_file in

@expose(template="tg.templates.welcome_one")
   def scarica_file(self):
        import time
        return dict(now=time.ctime())

and i change this :
 link1 =Element('a', href='/scarica_file')


all work, so is not true that he never find the path scarica_file but
i have make others mistake, can you help me?

thanks Luca



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: The path '/scarica_file' was not found.

by Christopher Arndt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


luca72 schrieb:

> @expose()
>     def scarica_file(self, ID):
>         from cherrypy.lib.cptools import serve_file
>         import os
>         dir_corrente = os.getcwd()
>         b= Musica.get(ID)
>         nome = b.nome_file
>         nome_band = b.band
>         return serve_file('/static/'+nome_band+'/'+nome,"application/x-
> download", "attachment")

serve_file() takes the *filename* of the file to serve, NOT the URL of
the file.

You can get the path of your "static" directory like this:

    from os.path import join, normpath
    import pkg_resources

    static_dir = pkg_resources.resource_file('mypkg', 'static')

    filename = join(normpath(static_dir), nome_band, nome)


HTH, Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: The path '/scarica_file' was not found.

by Christopher Arndt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Christopher Arndt schrieb:
> You can get the path of your "static" directory like this:
>
>     from os.path import join, normpath
>     import pkg_resources
>
>     static_dir = pkg_resources.resource_file('mypkg', 'static')
>
>     filename = join(normpath(static_dir), nome_band, nome)

Correction: actually it is better to get the path of the static dir from
the configuration, in case it was changed from the default. See the wiki
for an (updated) explanation:

http://docs.turbogears.org/1.0/StaticFiles#using-the-serve-file-function

NB: In your use case it might actually be better to just generate a URL
to the files in the static directory and let CherryPy serve the files
through the normal static filter mechanism or, even better, let them be
served by Apache or another web server via a RewriteRule or sth similar.

def crea_link_azioni_file(musica_obj):
    from elementtree.ElementTree import Element
    span = Element("span")
    link1 = Element('a', href='/static/%s/%s' %
        (musica_obj.nome_band, musica_obj.nome_file))
    ...
    return span

Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: The path '/scarica_file' was not found.

by luca72 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello and many thanks for your help:

I have also solve in this way but i'm sure that your are better:

dir_corrente = os.getcwd()
        b= Musica.get(ID)
        nome = b.nome_file
        nome_band = b.band
        return serve_file(dir_corrente + '/static/'+nome_band
+'/'+nome,"application/x-download", "attachment")

thanks

Luca

On 25 Set, 19:59, Christopher Arndt <chris.ar...@...> wrote:

> Christopher Arndt schrieb:
>
> > You can get the path of your "static" directory like this:
>
> >     from os.path import join, normpath
> >     import pkg_resources
>
> >     static_dir = pkg_resources.resource_file('mypkg', 'static')
>
> >     filename = join(normpath(static_dir), nome_band, nome)
>
> Correction: actually it is better to get the path of the static dir from
> the configuration, in case it was changed from the default. See the wiki
> for an (updated) explanation:
>
> http://docs.turbogears.org/1.0/StaticFiles#using-the-serve-file-function
>
> NB: In your use case it might actually be better to just generate a URL
> to the files in the static directory and let CherryPy serve the files
> through the normal static filter mechanism or, even better, let them be
> served by Apache or another web server via a RewriteRule or sth similar.
>
> def crea_link_azioni_file(musica_obj):
>     from elementtree.ElementTree import Element
>     span = Element("span")
>     link1 = Element('a', href='/static/%s/%s' %
>         (musica_obj.nome_band, musica_obj.nome_file))
>     ...
>     return span
>
> Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!