| | 11 | |
| | 12 | def _get_prefix(): |
| | 13 | """ |
| | 14 | Figures out the prefix for the calling URLconf module. |
| | 15 | |
| | 16 | If the calling URLconf is at: |
| | 17 | myproject.apps.polls.urls |
| | 18 | the returned prefix will be: |
| | 19 | myproject.apps.polls.views.polls |
| | 20 | """ |
| | 21 | f = sys._getframe(2) |
| | 22 | module = f.f_globals["__name__"] |
| | 23 | segs = module.split(".") |
| | 24 | # get rid of the 'urls' segment |
| | 25 | segs.pop() |
| | 26 | # now the last segment is the apps name |
| | 27 | app_name = segs[-1] |
| | 28 | # inject the 'views' module |
| | 29 | segs.append("views") |
| | 30 | # add the apps name to the end |
| | 31 | segs.append(app_name) |
| | 32 | # return the generated prefix |
| | 33 | return ".".join(segs) |
| | 34 | |