Cleverlemming
Cleverlemming

Reputation: 1370

Redirect to different App view directory from urls.py

I have URL definitions in my wagtail blog's app directory(blog/urls.py), and I would like to reference a view in my search app directory (search/views.py). The current URL definition is url(r'^search/$', search, name='search'). I don't want to duplicate common search views in every app's views file. How do I format the URL in my blog app to use the search view in search/views.py?

Upvotes: 0

Views: 390

Answers (1)

Prakhar Trivedi
Prakhar Trivedi

Reputation: 8526

Assuming that the blog app and search app are in the same level in project path directory, You can use relative import like this:

from django.conf.urls import url, patterns 
from search.views import search

urlpatterns = patterns(
    url(r'^search$', search ,  name='search'),

)

Upvotes: 1

Related Questions