This is my routes.py:

# -*- coding: utf-8 -*-
routers = dict(\
  BASE = dict(\
    default_controller = 'default', \
    default_function = 'index', \

    domains = {\
      'website.dev':'website', \
      'panel.website.dev':'website_panel', \
    }, \

    root_static = ['robots.txt'], \
    map_static = True, \
    exclusive_domain = True, \
  )\
)

The "website" application has a function called "article", defined in the 
default.py controller. 
That function renders the view for an article, which id is received in the 
first argument, as an integer. 
In order to generate the link to each article, I've defined Virtual Method 
on the "articles" table, like this:

db.articles.url = Field.Method(lambda row: \
  URL('default', 'article', args=row.articles.id, scheme=True, 
host='website.dev')) 


When I call that method from any place (controllers, views), the link 
generated is ok (doesn't include app name neither default controller). This 
is how I call the method:

for article in db(db.articles).select():
    print article.url()

This is an example of a link generated:
http://website.dev/article/425

But when I call the same method from a function defined on 
models/scheduler.py, the link generated includes the app name, like this:
http://website.dev/website/article/425

Both links work ok, but I think it's not good to have multiple links with 
same content (counter-productive for SEO, I think). 
I'm using nginx. Now I don't have any rewrite rule. I know I could write 
some rule to let nginx remove the appname from the url, but I'm still 
wondering why the virtual method is including the app name when called from 
scheduled task.

El sábado, 25 de abril de 2015, 9:52:39 (UTC-3), Niphlod escribió:
>
> there's nothing fancy in the scheduler that alters the environment at 
> runtime: it's no different from a web2py shell. can you post your routes, 
> your "desired urls" and the code that generates them ?
>
> On Friday, April 24, 2015 at 6:37:43 PM UTC+2, Lisandro wrote:
>>
>> I'm using parametric based routes for mapping each domain with its 
>> corresponding app. Because of this, when I use the URL() helper, the 
>> application name isn't included in the resulting url, and that is perfect 
>> for me. However, inside a scheduled task, the URL() helper generates urls 
>> including the app name. 
>>
>> Both urls (with and without application name) work ok. But considering 
>> they are urls for public content, I don't like the idea of having two 
>> different urls with the same content, I think it could be 
>> counter-productive for SEO and related stuff.
>>
>> Is there a way to avoid the inclusing of app name in urls generated from 
>> sheduled tasks?
>>
>

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to