I was wondering how I define in my controller "get-started" url;
If I define in my controller
def get-started():
return dict()
Its invalid; so I have to maybe use routes.py to rewrite it to just
getstarted()?
Is this the right approach;
Thanks
I get invalid request; but I will check again; perhaps I have a typo.
I am using trunk;
I am defining
def get_started():
return dict()
def features():
return dict()
when I call /app/default/get-started
I get invalid request;
when I call
/app/default/features
It works perfectly;
Maybe a bug?
On 3/31/11 10:31 AM, Ross Peoples wrote:
calling app/default/get_started
works also;
On 3/31/11 10:31 AM, Ross Peoples wrote:
The easiest thing to do is not use hyphens; make it get_started, perhaps.
Alternatively, the new router will by default let you use get-started in the URL, and translate it to get_started internally.
The hyphen-underscore translation works only if you're running the new router.
Thanks I will rename router.py.example to routes.py in the web 2 py root and then I can also make a copy in my app to do specific routing?
Jonathan mentioned that in his post.
VP is suggesting the opposite default, and I think perhaps he's right. It causes too much confusion.
Perhaps so.
FWIW, though, it's not a question of correcting a syntax error. The motivation is that underscores in URLs are unattractive, hard to type, and often hard to read (because of link underlining). The translation option is for having better-looking URLs.
Here's a suggestion for everyone who is using the new parametric router: if you care about hyphen translation one way or the other, turn it on or off explicitly for now, so a change to the default doesn't bite you. This is *only* a concern if you have (internally) underscores in your a/c/f names.
Hyphen/dash is a minus sign. You can't define a Python variable or
function that has a hyphen/dash. It's syntactically incorrect. I do
not think it's web2py's place to automatically fix this syntactical
error.
Well, functions for sure. I'm not sure about applications and controllers.
What's the recommendation on app names? Should we aim for app names that are valid Python names? If, for example, you want to import a module from another app, does the app name have to be a valid Python name?
What if they want hyphens? While app names are indeed file names, they're also used for other purposes within web2py. As somebody pointed out, they might well appear in an import statement, in which case they'd need to be valid Python identifiers--no hyphens.
I think we ought to stay safe and require that a/c/f all be valid Python identifiers, and give users the option of presenting underscores as hyphens in URLs. I agree, though, that translation should probably not be the default (as it is now).
In that case, you'd either want to turn off hyphen translation or use the Apache rewrite function.
BTW, I see that web2py's local_import function uses the application name as part of a module name. So app names must be legal Python module identifiers.
> I guess I can see leaving the default to re-map hyphens to underscores but
> perhaps only on functions?
YES.
App names are file names, and people generally don't want to have
hyphens in their file names, which is the opposite of what they would
want for URLs.
As for app names, I think they should be left alone because the
typical convention for file naming is underscored, which is the
opposite of what is desired for URLs. In other words, if people name
their files with underscores, it wouldn't be reasonable to assume they
want hyphens.
What if they want hyphens? While app names are indeed file names, they're also used for other purposes within web2py. As somebody pointed out, they might well appear in an import statement, in which case they'd need to be valid Python identifiers--no hyphens.
I think we ought to stay safe and require that a/c/f all be valid Python identifiers, and give users the option of presenting underscores as hyphens in URLs. I agree, though, that translation should probably not be the default (as it is now).