[Answer]-Django Admin Page Links Broken

1👍

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)),
👤knbk

Leave a comment