2

How do I rename an existing application in web2py with a hyphen?

For instance, I want to rename the welcome application to my-app. I tried by simply renaming the /applications/welcome folder to /applications/my-app, however, this just removed the welcome app from the admin and when I try to access the url:

http://localhost:8000/my-app/default/index

I get the message:

invalid request
bad_coder
  • 11,289
  • 20
  • 44
  • 72
guaranteed.site
  • 101
  • 1
  • 9
  • 1
    @Marcin it's fairly silly for you to vote down the question. In fact, it is immature without providing an answer. You can just say, "I don't know." If it was easy to find in the documentation, I wouldn't have asked. Please don't talk when you haven't done the homework yourself. Thank you. – guaranteed.site Jul 06 '13 at 18:11
  • @Marcin please do read above and try being constructive. Thanks. – guaranteed.site Jul 06 '13 at 18:14
  • I've read your question. My *constructive* feedback to you is that productive professionals actually try to research their problems before running to SO. It's usually quicker, and you'll learn more. – Marcin Jul 06 '13 at 18:15
  • still, no answer. I won't keep up the conversation with you any longer, little boy. If someone knows a solution, please enlighten the community. It is actually not as simple as removing an application. Thanks. – guaranteed.site Jul 06 '13 at 18:21
  • 1
    Now you're using epithets and putting words in my mouth. I'm sure people will be delighted to help you. – Marcin Jul 06 '13 at 18:26
  • 2
    For what it's worth, I don't think this issue was easily resolvable by turning to the documentation. Seems like a reasonable question to ask here. – Anthony Jul 08 '13 at 15:57

2 Answers2

5

As it turns out, web2py has problems with folder names with hyphens in the application directory. I noticed when creating the app my-app via the admin interface, it instead created an app named my_app.

Any application with a hyphen in its name will not be recognized by web2py!

This is related to the fact that a valid identifier in python can only contain letters, numbers, and underscores.

If a hyphen must be used in the url, the solution is setting the map_hyphen dict value to True in the routes.py file either at the base directory or an app-specific location This will convert incoming hyphens in url request to underscores, and then change outgoing underscores in your directory structure to hyphens in the URL. By default, this behavior is set to False in the default router.

I hope this saves someone from a headache if you happen to be changing, say, the welcome scaffold to something with a hyphen. ;)

guaranteed.site
  • 101
  • 1
  • 9
1

Try clicking the "Reload routes" button in the upper right of the admin app home page, or re-start the server.

Anthony
  • 25,466
  • 3
  • 28
  • 57