Задать вопрос

Тел: +7 965 3737 888

501

Просмотров

2

Ответов

Allow configurable subdirectory django deployment

I wanted a way to deploy a Django site to both the root of a domain, and to a subdirectory. The solution was to loop over all urlpatterns and add a configurable string (URL_PREFIX) at the beginning of all patterns.

Вопрос полезен? Да0/Нет0
file_3158.py(470.0б)
None

Ответы (2):

Ответemilstenstrom:12.02.2013
Ответ полезен? Да0/Нет0

@lallulli: I agree, your solution is much better!

Ответlallulli:27.10.2010
Ответ полезен? Да0/Нет0

I suggest another way, which is simpler and more pythonic IMHO.

In your urls.py rename urlpatterns to base_urlpatterns; then add the followinig definition at the end of the same file:

urlpatterns = patterns('',
    '^', include(base_urlpatterns), # iff you wish to maintain the un-prefixed URL's too
    '^your_prefix/', include(base_urlpatterns),
)