2

In my project I have one app which have its own urls.py like this

urlpatterns = patterns('',
(r'^(?P<language>\w+)/$', 'MainSite.views.home_page'),)

(above file is in my application )

I am trying include this file in main(project's) urls.py like this :

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'', include('myproject.MainSite.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

if settings.DEBUG :
    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', 
{'document_root': settings.MEDIA_ROOT}),
        )

but after this I can able to call the MainSite's (app's) view but my admin url is not working I tried

urlpatterns = patterns('',
        (r'^$', include('myproject.MainSite.urls')),
        url(r'^admin/', include(admin.site.urls)),
    )

but after this this makes admin work but my app's view won't get called, how do I solve this.

0

1 Answer 1

10

You're including your views at the root level. Since it comes before the urlpattern for the admin, the first urlpattern catches everything, so nothing is ever passed to the admin views.

The simplest fix is to simply reverse the order:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    (r'', include('myproject.MainSite.urls')),
)

Then, your views will only catch anything the admin doesn't.

Sign up to request clarification or add additional context in comments.

1 Comment

@abhishekworld you might consider accepting the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.