preetam
preetam

Reputation: 1587

Changing between applications in a django site

I have 2 applications in my site:

The main url conf always raises urls with the appname of base/index.html When a url action say href="login" is provided from base/index.html it automatically searches for "base/login.html"

I want it to switch the application and search for "users/login.html"

How do I force it to switch applications either in the html href or in the urlconf. I prefer to use url conf but don't konw how to.

users/url.py

from django.conf.urls import patterns, include, url
from emp_users.views import *
from django.conf import settings
from django.views.generic.base import RedirectView

urlpatterns = patterns('',
    url(r'^index/$', RedirectView.as_view(url='/hr_base/index', permanent=False), name='index'),
    url(r'^new_user/$', register_user),
    url(r'^new_hr_user/$', register_hr_user),
)

site/urls.py : This is the main project urls.py

urlpatterns = patterns('',
    url(r'^base/index$','hr_base.views.index'),
    url(r'^users/', include('emp_users.urls')),
)
urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT},),# 'show_indices':True}),
)

site/base/templates/base/index.html

<a href="login">Login</a>

That should pointgenerate the url users/login and then access user/views.py

Upvotes: 1

Views: 1271

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599778

Django is not adding any URLs anywhere. You are simply providing a relative URL in your template, so your browser is adding the current path to it. If you want to specify a different path, then you need to provide that full URL: <a href="/users/new_user">.

However you should not be hard-coding URLs in your templates in any case. You should let Django provide the full URL:

<a href="{% url 'login' %}">Login</a>

Upvotes: 3

simar
simar

Reputation: 1832

urlpatterns = patterns('',
    url(r'^base/login/$', 'base.views.login'),
    url(r'^users/login/$', 'users.views.login')  
)

or in main url.py file

urlpatterns = patterns('',
    url(r'^base/', include('base.url'),
    url(r'^users/', include('users.url') ,
)

Upvotes: 1

Related Questions