Domanda

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
È stato utile?

Soluzione

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. ;)

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top