sdweldon
sdweldon

Reputation: 190

Django Admin Page Links Broken

I am running Django on Apache (on localhost). The admin page works fine, my issue is with every link on this page. Since a shareroom hosted on our servers uses /admin/, in order to reach my Django admin page i had to change the following in urls.py :

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

TO

urlpatterns = patterns('',
    url(r'/control/', include(admin.site.urls)),
)

However, now when I click on any link on the page (such as Groups under Auth), it brings me to control/auth/group/ in the browser, instead of http://localhost/django_ngs/control/auth/group/ . I must be missing a connection to admin after I changed the url. I have to append the project part of the url but am not sure how. Any ideas? Thank you in advance.

Edit: Basically it is NOT appending the destination to the current link. The links point to control/auth/group/ instead of http://localhost/django_ngs/control/auth/group/ or /control/auth/group/

Edit 2: I can only reach my admin page using the r'/control/' format (with a slash in front), whereas it SHOULD be r'^control/', with a carrot in front. This could be related to my issue (thanks knbk) Any ideas?

Edit 3: This is my entire urls.py

 from django.conf.urls import patterns, include, url
 from django.contrib import admin
 # Uncomment the next two lines to enable the admin:
 from django.contrib import admin
 admin.autodiscover()

 urlpatterns = patterns('',
     url(r'/control/', include(admin.site.urls)),
 )

When I go to the admin page using the carrot, I get this:

Upvotes: 0

Views: 837

Answers (1)

knbk
knbk

Reputation: 53649

Your problem is in the django_ngs/ prefix to your urls. Django doesn't know about it, and all url patterns are root-relative.

Now, the string django_ngs/control/ matches the regex r'/control/'. If you include a carot in the regex (r'^control/'), you require the string to start with the supplied pattern. This is generally what you want. E.g. if you later on add another app with all urls under /something/, and you need to add a page in that app named /something/control/, the url would still only match the first root-level page, not the second page in /something/.

The reason your links get broken, is because Django reverses the url pattern back to an url, but the pattern doesn't describe the django_ngs/ prefix in any way. So, it gets left out in the generated url.

There are two solutions here. Either you prefix each pattern with django_ngs/, i.e:

url(r'^django_ngs/control/', include(admin.site.urls)),

Or you can move the complete url configuration to another file, and include it in your main url config under django_ngs/:

url(r'^django_ngs/', include(myproject.other.file)),

Upvotes: 1

Related Questions