2

Is there a way to split the url mappings in multiple files in Google App Engine?

I want something like this:

from app1.controller import App1Handler
from app2.controller import App2Handler

app = webapp2.WSGIApplication([(r'/app1', App1Handler),(r'/app1', App2Handler)])

In App1Handler, I would like to specify some thing like this:

(r'/action1', Action1Handler), (r'/action2', Action2Handler)

In summary, when user access /app1/action1, Action1Handler has to be executed.

Django has a similar feature, where admin site urls are included in the main url patterns.

urlpatterns = patterns('',
    url(r'^polls/$', 'polls.views.index'),
    url(r'^admin/', include(admin.site.urls)),
)

Is there any such provisions available in GAE?

2 Answers 2

1

You can split between the 2 files at the app.yaml level:

- url: /app1/.*
  script: file1.py
- url: /app2/.*
  script: file2.py

I think you will still need to add /app1 in all your urls in the file1.py files e.g.

app = webapp2.WSGIApplication([(r'/app1/myview', Handler),(r'/app1/myotherview', AnotherHandler)])

I think this is better because you can use handlers with the same name in the 2 modules, whereas you would get a conflict if you imported 2 handlers with the same name in a main file.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks user375348. I am aware about redirection in app.yaml, however, wondered whether GAE supports multiple url mappings across files. Anyway, Thanks again for your kind reply.
1

You could do what @user375348 described by using app.yaml, otherwise you'd need to build your own. There's an simple router in the webapp2 documentation you can pretty much use straight up.

http://webapp-improved.appspot.com/guide/handlers.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.