python - django how to place variable in a raw string,such as for URL router -



python - django how to place variable in a raw string,such as for URL router -

i want write url configured when needed,for example:

url(r'^api/v1/books/',include('article.urls'))

in settings.py set apiversion = 'api/v1'

i want set apiversion url create configureable,how that,is there best way accomplish that?

in urls.py:

from django.conf import settings urlpattern = patterns('', url(settings.apiversion, include( url(r'/books/',include('article.urls'), ) )

in settings.py:

apiversion = r'^api/v1'

you can avoid nested include using variable.

python django django-urls

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -