All of my URLs in Django are coded relative to the root URL: /login/, /logout etc. I want to deploy the app to the sub url : www.example.com/app, and I want the URLs to be www.example.com/app/login/, www.example.com/app/logout. How do I do this efficiently?
1 Answer
You must modify your hard coded links to use Django's reversal methods. For example, instead of
<a href="/login/">Login</a>
you should use
<a href="{% url 'accounts_login' %}">Login</a>
this will allow Django to dynamically determine the URLs with respect to the root URL.
2 Comments
Dzung Nguyen
Can you please provide more information? I defined url as url(r'^$', interface_page, name = 'index'), and call them from template but it's not working yet. My urls are: /login, /logout, /profile/, /profile/change, and /profile/delete.
Selcuk
You must use the
name of your URLs, like {% url 'index' %} when constructing your links in the templates. See docs.djangoproject.com/en/1.7/topics/http/urls/… for details.